-
Notifications
You must be signed in to change notification settings - Fork 24.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Migrate from native CallInvoker to NativeMethodCallInvoker #37473
Conversation
This pull request was exported from Phabricator. Differential Revision: D45891627 |
…37473) Summary: Pull Request resolved: facebook#37473 ## Context The TurboModule system uses a CallInvoker interface to schedule JavaScript → native, and native → JavaScript calls. ## Problem JavaScript → native and native → JavaScript calls are different. They can have different behaviours/properties. And, in the future, we might want to evolve them differently. e.g: - JavaScript → native **always** have a method name. Native → JavaScript calls don't. - Native → JavaScript can have priorities, since D41492849. JavaScript → native don't. ## Changes Instead of tying both types of calls to the CallInvoker abstraction, this diff creates a **separate** abstraction for Native → JavaScript calls: NativeMethodCallInvoker. This way, we can evolve both abstractions separately over time: - We can evolve the CallInvoker abstraction to suit the needs of JavaScript → native calls. - We can evolve the NativeMethodCallInvoker abstraction to suite the needs of native → JavaScript calls. This ultimately makes TurboModule system more extensible. ## Motivation For the TurboModule interop layer on iOS, React Native needs to execute the "constantsToExport" method on the main queue, when the module requires main queue setup. (implementation: D45924977). The simplest way to implement this behaviour is to introduce a `methodName` to CallInvoker, and customize the legacy module's CallInvoker::invokeSync method, like so: ``` void invokeSync(std::string methodName, std::function<void()> &&work) override { if (requiresMainQueueSetup_ && methodName == "getConstants") { __block auto retainedWork = std::move(work); RCTUnsafeExecuteOnMainQueueSync(^{ retainedWork(); }); return; } work(); } ``` But, customizing CallInvoker to introduce a `methodName` parameter doesn't make sense: Native → JavaScript calls don't necessarily have method names. So, this diff forks CallInvoker into NativeMethodCallInvoker. That way, we can customize NativeMethodCallInvoker to introduce a method name (which does make sense) and resolve this problem. For the full solution, see D45924977. NOTE: Now that NativeMethodCallInvoker is different from CallInvoker, it might make sense to re-name CallInvoker back to JSCallInvoker. Differential Revision: D45891627 fbshipit-source-id: eea9761e4ab99019a5bcaeab2806568aac2bd936
This pull request was exported from Phabricator. Differential Revision: D45891627 |
…37473) Summary: Pull Request resolved: facebook#37473 ## Context The TurboModule system uses a CallInvoker interface to schedule JavaScript → native, and native → JavaScript calls. ## Problem JavaScript → native and native → JavaScript calls are different. They can have different behaviours/properties. And, in the future, we might want to evolve them differently. e.g: - JavaScript → native **always** have a method name. Native → JavaScript calls don't. - Native → JavaScript can have priorities, since D41492849. JavaScript → native don't. ## Changes Instead of tying both types of calls to the CallInvoker abstraction, this diff creates a **separate** abstraction for Native → JavaScript calls: NativeMethodCallInvoker. This way, we can evolve both abstractions separately over time: - We can evolve the CallInvoker abstraction to suit the needs of JavaScript → native calls. - We can evolve the NativeMethodCallInvoker abstraction to suite the needs of native → JavaScript calls. This ultimately makes TurboModule system more extensible. ## Motivation For the TurboModule interop layer on iOS, React Native needs to execute the "constantsToExport" method on the main queue, when the module requires main queue setup. (implementation: D45924977). The simplest way to implement this behaviour is to introduce a `methodName` to CallInvoker, and customize the legacy module's CallInvoker::invokeSync method, like so: ``` void invokeSync(std::string methodName, std::function<void()> &&work) override { if (requiresMainQueueSetup_ && methodName == "getConstants") { __block auto retainedWork = std::move(work); RCTUnsafeExecuteOnMainQueueSync(^{ retainedWork(); }); return; } work(); } ``` But, customizing CallInvoker to introduce a `methodName` parameter doesn't make sense: Native → JavaScript calls don't necessarily have method names. So, this diff forks CallInvoker into NativeMethodCallInvoker. That way, we can customize NativeMethodCallInvoker to introduce a method name (which does make sense) and resolve this problem. For the full solution, see D45924977. NOTE: Now that NativeMethodCallInvoker is different from CallInvoker, it might make sense to re-name CallInvoker back to JSCallInvoker. Differential Revision: D45891627 fbshipit-source-id: 6eca49a2ef452a567966687fd28901e4b76266ca
This pull request was exported from Phabricator. Differential Revision: D45891627 |
…37473) Summary: Pull Request resolved: facebook#37473 ## Context The TurboModule system uses a CallInvoker interface to schedule JavaScript → native, and native → JavaScript calls. ## Problem JavaScript → native and native → JavaScript calls are different. They can have different behaviours/properties. And, in the future, we might want to evolve them differently. e.g: - JavaScript → native **always** have a method name. Native → JavaScript calls don't. - Native → JavaScript can have priorities, since D41492849. JavaScript → native don't. ## Changes Instead of tying both types of calls to the CallInvoker abstraction, this diff creates a **separate** abstraction for Native → JavaScript calls: NativeMethodCallInvoker. This way, we can evolve both abstractions separately over time: - We can evolve the CallInvoker abstraction to suit the needs of JavaScript → native calls. - We can evolve the NativeMethodCallInvoker abstraction to suite the needs of native → JavaScript calls. This ultimately makes TurboModule system more extensible. ## Motivation For the TurboModule interop layer on iOS, React Native needs to execute the "constantsToExport" method on the main queue, when the module requires main queue setup. (implementation: D45924977). The simplest way to implement this behaviour is to introduce a `methodName` to CallInvoker, and customize the legacy module's CallInvoker::invokeSync method, like so: ``` void invokeSync(std::string methodName, std::function<void()> &&work) override { if (requiresMainQueueSetup_ && methodName == "getConstants") { __block auto retainedWork = std::move(work); RCTUnsafeExecuteOnMainQueueSync(^{ retainedWork(); }); return; } work(); } ``` But, customizing CallInvoker to introduce a `methodName` parameter doesn't make sense: Native → JavaScript calls don't necessarily have method names. So, this diff forks CallInvoker into NativeMethodCallInvoker. That way, we can customize NativeMethodCallInvoker to introduce a method name (which does make sense) and resolve this problem. For the full solution, see D45924977. NOTE: Now that NativeMethodCallInvoker is different from CallInvoker, it might make sense to re-name CallInvoker back to JSCallInvoker. Differential Revision: D45891627 fbshipit-source-id: 14a93431bc4674bf0a2eef1738bb77998a99ad07
This pull request was exported from Phabricator. Differential Revision: D45891627 |
1 similar comment
This pull request was exported from Phabricator. Differential Revision: D45891627 |
…37473) Summary: Pull Request resolved: facebook#37473 ## Context The TurboModule system uses a CallInvoker interface to schedule JavaScript → native, and native → JavaScript calls. ## Problem JavaScript → native and native → JavaScript calls are different. They can have different behaviours/properties. And, in the future, we might want to evolve them differently. e.g: - JavaScript → native **always** have a method name. Native → JavaScript calls don't. - Native → JavaScript can have priorities, since D41492849. JavaScript → native don't. ## Changes Instead of tying both types of calls to the CallInvoker abstraction, this diff creates a **separate** abstraction for Native → JavaScript calls: NativeMethodCallInvoker. This way, we can evolve both abstractions separately over time: - We can evolve the CallInvoker abstraction to suit the needs of JavaScript → native calls. - We can evolve the NativeMethodCallInvoker abstraction to suite the needs of native → JavaScript calls. This ultimately makes TurboModule system more extensible. ## Motivation For the TurboModule interop layer on iOS, React Native needs to execute the "constantsToExport" method on the main queue, when the module requires main queue setup. (implementation: D45924977). The simplest way to implement this behaviour is to introduce a `methodName` to CallInvoker, and customize the legacy module's CallInvoker::invokeSync method, like so: ``` void invokeSync(std::string methodName, std::function<void()> &&work) override { if (requiresMainQueueSetup_ && methodName == "getConstants") { __block auto retainedWork = std::move(work); RCTUnsafeExecuteOnMainQueueSync(^{ retainedWork(); }); return; } work(); } ``` But, customizing CallInvoker to introduce a `methodName` parameter doesn't make sense: Native → JavaScript calls don't necessarily have method names. So, this diff forks CallInvoker into NativeMethodCallInvoker. That way, we can customize NativeMethodCallInvoker to introduce a method name (which does make sense) and resolve this problem. For the full solution, see D45924977. NOTE: Now that NativeMethodCallInvoker is different from CallInvoker, it might make sense to re-name CallInvoker back to JSCallInvoker. Differential Revision: D45891627 fbshipit-source-id: 9a9a5309fe2681aa5a2523846ffcda6278bd0d4e
This pull request was exported from Phabricator. Differential Revision: D45891627 |
…37473) Summary: Pull Request resolved: facebook#37473 ## Context The TurboModule system uses a CallInvoker interface to schedule JavaScript → native, and native → JavaScript calls. ## Problem JavaScript → native and native → JavaScript calls are different. They can have different behaviours/properties. And, in the future, we might want to evolve them differently. e.g: - JavaScript → native **always** have a method name. Native → JavaScript calls don't. - Native → JavaScript can have priorities, since D41492849. JavaScript → native don't. ## Changes Instead of tying both types of calls to the CallInvoker abstraction, this diff creates a **separate** abstraction for Native → JavaScript calls: NativeMethodCallInvoker. This way, we can evolve both abstractions separately over time: - We can evolve the CallInvoker abstraction to suit the needs of JavaScript → native calls. - We can evolve the NativeMethodCallInvoker abstraction to suite the needs of native → JavaScript calls. This ultimately makes TurboModule system more extensible. ## Motivation For the TurboModule interop layer on iOS, React Native needs to execute the "constantsToExport" method on the main queue, when the module requires main queue setup. (implementation: D45924977). The simplest way to implement this behaviour is to introduce a `methodName` to CallInvoker, and customize the legacy module's CallInvoker::invokeSync method, like so: ``` void invokeSync(std::string methodName, std::function<void()> &&work) override { if (requiresMainQueueSetup_ && methodName == "getConstants") { __block auto retainedWork = std::move(work); RCTUnsafeExecuteOnMainQueueSync(^{ retainedWork(); }); return; } work(); } ``` But, customizing CallInvoker to introduce a `methodName` parameter doesn't make sense: Native → JavaScript calls don't necessarily have method names. So, this diff forks CallInvoker into NativeMethodCallInvoker. That way, we can customize NativeMethodCallInvoker to introduce a method name (which does make sense) and resolve this problem. For the full solution, see D45924977. NOTE: Now that NativeMethodCallInvoker is different from CallInvoker, it might make sense to re-name CallInvoker back to JSCallInvoker. Differential Revision: D45891627 fbshipit-source-id: 85296a17fe66af5655277b126a13323ae25203e9
3a36c5d
to
27f8a2e
Compare
This pull request was exported from Phabricator. Differential Revision: D45891627 |
This pull request was exported from Phabricator. Differential Revision: D45891627 |
…37473) Summary: Pull Request resolved: facebook#37473 ## Context The TurboModule system uses a CallInvoker interface to schedule JavaScript → native, and native → JavaScript calls. ## Problem JavaScript → native and native → JavaScript calls are different. They can have different behaviours/properties. And, in the future, we might want to evolve them differently. e.g: - JavaScript → native **always** have a method name. Native → JavaScript calls don't. - Native → JavaScript can have priorities, since D41492849. JavaScript → native don't. ## Changes Instead of tying both types of calls to the CallInvoker abstraction, this diff creates a **separate** abstraction for Native → JavaScript calls: NativeMethodCallInvoker. This way, we can evolve both abstractions separately over time: - We can evolve the CallInvoker abstraction to suit the needs of JavaScript → native calls. - We can evolve the NativeMethodCallInvoker abstraction to suite the needs of native → JavaScript calls. This ultimately makes TurboModule system more extensible. ## Motivation For the TurboModule interop layer on iOS, React Native needs to execute the "constantsToExport" method on the main queue, when the module requires main queue setup. (implementation: D45924977). The simplest way to implement this behaviour is to introduce a `methodName` to CallInvoker, and customize the legacy module's CallInvoker::invokeSync method, like so: ``` void invokeSync(std::string methodName, std::function<void()> &&work) override { if (requiresMainQueueSetup_ && methodName == "getConstants") { __block auto retainedWork = std::move(work); RCTUnsafeExecuteOnMainQueueSync(^{ retainedWork(); }); return; } work(); } ``` But, customizing CallInvoker to introduce a `methodName` parameter doesn't make sense: Native → JavaScript calls don't necessarily have method names. So, this diff forks CallInvoker into NativeMethodCallInvoker. That way, we can customize NativeMethodCallInvoker to introduce a method name (which does make sense) and resolve this problem. For the full solution, see D45924977. NOTE: Now that NativeMethodCallInvoker is different from CallInvoker, it might make sense to re-name CallInvoker back to JSCallInvoker. Changelog: [Category][Breaking] - Introduce NativeMethodCallInvoker to replace the TurboModule system's native CallInvoker Reviewed By: javache Differential Revision: D45891627 fbshipit-source-id: f7993cb5f7a2bba9d07a7dc8322ed5472a4036b7
This pull request was exported from Phabricator. Differential Revision: D45891627 |
…37473) Summary: Pull Request resolved: facebook#37473 ## Context The TurboModule system uses a CallInvoker interface to schedule JavaScript → native, and native → JavaScript calls. ## Problem JavaScript → native and native → JavaScript calls are different. They can have different behaviours/properties. And, in the future, we might want to evolve them differently. e.g: - JavaScript → native **always** have a method name. Native → JavaScript calls don't. - Native → JavaScript can have priorities, since D41492849. JavaScript → native don't. ## Changes Instead of tying both types of calls to the CallInvoker abstraction, this diff creates a **separate** abstraction for Native → JavaScript calls: NativeMethodCallInvoker. This way, we can evolve both abstractions separately over time: - We can evolve the CallInvoker abstraction to suit the needs of JavaScript → native calls. - We can evolve the NativeMethodCallInvoker abstraction to suite the needs of native → JavaScript calls. This ultimately makes TurboModule system more extensible. ## Motivation For the TurboModule interop layer on iOS, React Native needs to execute the "constantsToExport" method on the main queue, when the module requires main queue setup. (implementation: D45924977). The simplest way to implement this behaviour is to introduce a `methodName` to CallInvoker, and customize the legacy module's CallInvoker::invokeSync method, like so: ``` void invokeSync(std::string methodName, std::function<void()> &&work) override { if (requiresMainQueueSetup_ && methodName == "getConstants") { __block auto retainedWork = std::move(work); RCTUnsafeExecuteOnMainQueueSync(^{ retainedWork(); }); return; } work(); } ``` But, customizing CallInvoker to introduce a `methodName` parameter doesn't make sense: Native → JavaScript calls don't necessarily have method names. So, this diff forks CallInvoker into NativeMethodCallInvoker. That way, we can customize NativeMethodCallInvoker to introduce a method name (which does make sense) and resolve this problem. For the full solution, see D45924977. NOTE: Now that NativeMethodCallInvoker is different from CallInvoker, it might make sense to re-name CallInvoker back to JSCallInvoker. Changelog: [Category][Breaking] - Introduce NativeMethodCallInvoker to replace the TurboModule system's native CallInvoker Reviewed By: javache Differential Revision: D45891627 fbshipit-source-id: b650738d2333e8728c6e96c7f7ac3e6a899136e3
This pull request was exported from Phabricator. Differential Revision: D45891627 |
Base commit: d470dee |
This pull request has been merged in b70f186. |
Summary:
Context
The TurboModule system uses a CallInvoker interface to schedule JavaScript → native, and native → JavaScript calls.
Problem
JavaScript → native and native → JavaScript calls are different. They can have different behaviours/properties. And, in the future, we might want to evolve them differently. e.g:
Changes
Instead of tying both types of calls to the CallInvoker abstraction, this diff creates a separate abstraction for Native → JavaScript calls: NativeMethodCallInvoker.
This way, we can evolve both abstractions separately over time:
This ultimately makes TurboModule system more extensible.
Motivation
For the TurboModule interop layer on iOS, React Native needs to execute the "constantsToExport" method on the main queue, when the module requires main queue setup. (implementation: D45924977).
The simplest way to implement this behaviour is to introduce a
methodName
to CallInvoker, and customize the legacy module's CallInvoker::invokeSync method, like so:But, customizing CallInvoker to introduce a
methodName
parameter doesn't make sense: Native → JavaScript calls don't necessarily have method names. So, this diff forks CallInvoker into NativeMethodCallInvoker. That way, we can customize NativeMethodCallInvoker to introduce a method name (which does make sense) and resolve this problem. For the full solution, see D45924977.NOTE: Now that NativeMethodCallInvoker is different from CallInvoker, it might make sense to re-name CallInvoker back to JSCallInvoker.
Differential Revision: D45891627