Summary:
The JavaScript ecosystem doesn't have the notion of a built-in native module loader. Even Node is decoupled from its module loader. The module loader system is just JS that runs on top of the global `process` object which has all the built-in goodies.
Additionally there is no such thing as a global require. That is something unique to our providesModule system. In other module systems such as node, every require is contextual. Even registered npm names are localized by version.
The only global namespace that is accessible to the host environment is the global object. Normally module systems attaches itself onto the hooks provided by the host environment on the global object.
Currently, we have two forms of dispatch that reaches directly into the module system. executeJSCall which reaches directly into require. Everything now calls through the BatchedBridge module (except one RCTLog edge case that I will fix). I propose that the executors calls directly onto `BatchedBridge` through an instance on the global so that everything is guaranteed to go through it. It becomes the main communication hub.
I also propose that we drop the dynamic requires inside of MessageQueue/BatchBridge and instead have the modules register themselves with the bridge.
executeJSCall was originally modeled after the XHP equivalent. The XHP equivalent was designed that way because the act of doing the call was the thing that defined a dependency on the module from the page. However, that is not how React Native works.
The JS side is driving the dependencies by virtue of requiring new modules and frameworks and the existence of dependencies is driven by the JS side, so this design doesn't make as much sense.
The main driver for this is to be able to introduce a new module system like Prepack's module system. However, it also unlocks the possibility to do dead module elimination even in our current module system. It is currently not possible because we don't know which module might be called from native.
Since the module system now becomes decoupled we could publish all our providesModule modules as npm/CommonJS modules using a rewrite script. That's what React Core does.
That way people could use any CommonJS bundler such as Webpack, Closure Compiler, Rollup or some new innovation to create a JS bundle.
This diff expands the executeJSCalls to the BatchedBridge's three individual pieces to make them first class instead of being dynamic. This removes one layer of abstraction. Hopefully we can also remove more of the things that register themselves with the BatchedBridge (various EventEmitters) and instead have everything go through the public protocol. ReactMethod/RCT_EXPORT_METHOD.
public
Reviewed By: vjeux
Differential Revision: D2717535
fb-gh-sync-id: 70114f05483124f5ac5c4570422bb91a60a727f6
Summary: public
The `bridge.modules` dictionary provides access to all native modules, but this API requires that every module is initialized in advance so that any module can be accessed.
This diff introduces a better API that will allow modules to be initialized lazily as they are needed, and deprecates `bridge.modules` (modules that use it will still work, but should be rewritten to use `bridge.moduleClasses` or `-[bridge moduleForName/Class:` instead.
The rules are now as follows:
* Any module that overrides `init` or `setBridge:` will be initialized on the main thread when the bridge is created
* Any module that implements `constantsToExport:` will be initialized later when the config is exported (the module itself will be initialized on a background queue, but `constantsToExport:` will still be called on the main thread.
* All other modules will be initialized lazily when a method is first called on them.
These rules may seem slightly arcane, but they have the advantage of not violating any assumptions that may have been made by existing code - any module written under the original assumption that it would be initialized synchronously on the main thread when the bridge is created should still function exactly the same, but modules that avoid overriding `init` or `setBridge:` will now be loaded lazily.
I've rewritten most of the standard modules to take advantage of this new lazy loading, with the following results:
Out of the 65 modules included in UIExplorer:
* 16 are initialized on the main thread when the bridge is created
* A further 8 are initialized when the config is exported to JS
* The remaining 41 will be initialized lazily on-demand
Reviewed By: jspahrsummers
Differential Revision: D2677695
fb-gh-sync-id: 507ae7e9fd6b563e89292c7371767c978e928f33
Summary: public
Add RCTFatal for reporting fatal runtime conditions. This centralizes failure handling to one function and allows you to customize how they should be handled. RCTFatal will be logged to the console and as a redbox and will also be triggered by fatal exceptions coming from RCTExceptionsManager.
Note that there is no RCTLogFatal, since just logging the fatal condition does not allow us to handle it consistently.
Reviewed By: nicklockwood
Differential Revision: D2615490
fb-gh-sync-id: 7d8e134419e10a8fb549297054ad955db3f6bee0
Summary: public
Added lightweight genarics annotations to make the code more readable and help the compiler catch bugs.
Fixed some type bugs and improved bridge validation in a few places.
Reviewed By: javache
Differential Revision: D2600189
fb-gh-sync-id: f81e22f2cdc107bf8d0b15deec6d5b83aacc5b56
Summary:
For the sake of consistency, `cmd+r` should just post a refresh notification. This way other tools can also observe and react to the refresh without ugly hacks.
Closes https://github.com/facebook/react-native/pull/2175
Github Author: Tj <tfallon@mail.depaul.edu>
Summary:
Moved the view creation & property binding logic out of RCTUIManager into a separate RCTComponentData class - this follows the pattern used with the bridge.
I've also updated the property binding to use pre-allocated blocks for setting the values, which is more efficient than the previous system that re-contructed the selectors each time it was called. This should improve view update performance significantly.
Summary:
Add a new bridge delegate protocol to allow a more flexible bridge configuration.
For now it just support the pre-existent configurations + providing the JavaScript
source to the bridge, that should allow pre-loading sources.
Summary:
Occasionally people create RCTBridgeModule subclasses or base classes that are not intended to be accessed from JS, and so they don't export them. This was previously flagged as an error by the system. I've now downgraded this error to a warning at startup, and deferred the redbox error until the module is directly accessed by native or JS code.
Summary:
Remove `RCTGetExecutorID` and `RCTSetExecutorID`, it wasn't used anymore since
the bridge was refactored into `RCTBridge` and `RCTBatchedBridge`.
Summary:
@public
The info about bridge modules (such as id, name, queue, methods...) was spread
across arrays & dictionaries on the bridge, move it into a specific class.
It also removes a lot of information that was statically cached, and now have
the same lifecycle of the bridge.
Also moved RCTModuleMethod, RCTFrameUpdate and RCTBatchedBridge into it's own
files, for organization sake.
NOTE: This diff seems huge, but most of it was just moving code :)
Test Plan:
Tested UIExplorer & UIExplorer tests, Catalyst, MAdMan and Groups. Everything
looks fine.
Summary:
@public
I've added an alert to notify when the profile has been generated, but it was
being created out of the main thread.
Test Plan:
Launch the UIExplorer, start and stop profiling, an alert should show up, and
everything should just keep working as expected.
Summary:
@public
When the profile is initialized, it automatically hooks into every method of
the bridge modules, that was causing `+initialize` to be called twice.
Also add a popup to notify the user that the profile has been created.
Test Plan:
Run the UIExplorer, start the profiler, try to rage shake to open the dev menu
again. It should now work, and show an alertview with some information once the
profile is stopped.
Summary:
Live reload is disabled when an error has occurred. This requires the developer to fix the error and then switch to the simulator to reload the device manually; impacting developer flow and increasing alt tabbing. This pull request fixes that by allowing live reload to work even on errors.
This fixes issue: #1343.
Closes https://github.com/facebook/react-native/pull/1549
Github Author: Ruben Niculcea <ruben.niculcea@gmail.com>
Test Plan: Imported from GitHub, without a `Test Plan:` line.
Summary:
@public
That was eventually being released before all the queues had been cleared.
Update it so the each modules' queue is immediately invalidated after sending
the `-invalidate` message to it, and introduce an intentional retain cycle so
the bridge is only released together with all modules, when all the messages
have been dispatched.
Test Plan: Launch the UIExplorer, and reload it, like, a lot.
Summary:
@public
Add PerformanceLogger to keep track of JS download, initial script execution and
full TTI.
Test Plan:
The Native side currently calls `addTimespans` when it's finish initializing
with the six values (start and end for the three events), so I just checked it
with a `PerformanceLogger.logTimespans()` at the end of the function.
```
2015-06-18 16:47:19.096 [info][tid:com.facebook.React.JavaScript] "ScriptDownload: 48ms"
2015-06-18 16:47:19.096 [info][tid:com.facebook.React.JavaScript] "ScriptExecution: 106ms"
2015-06-18 16:47:19.096 [info][tid:com.facebook.React.JavaScript] "TTI: 293ms"
```
Summary:
@public
Add marker to show JavaScript download duration + flow arrows to show the origin
of the UI blocks being flushed.
Also fixed the condition on `RCTPerfStats`, UI and JS graphs were being created
at startup time, now they're just created on the first time they're shown.
Test Plan:
The markers:
{F22577660}
To check the FPS graph, enable it on the DevMenu, and it should appear initially
empty, instead of previously filled as before.
Summary:
@public
The current implementation of `MessageQueue` is huge, over-complicated and spread
across `MethodQueue`, `MethodQueueMixin`, `BatchedBridge` and `BatchedBridgeFactory`
Refactored in a simpler way, were it's just a `MessageQueue` class and `BatchedBridge`
is only an instance of it.
Test Plan:
I had to make some updates to the tests, but no real update to the native side.
There's also tests covering the `remoteAsync` methods, and more integration tests for UIExplorer.
Verified whats being used by Android, and it should be safe, also tests Android tests have been pretty reliable.
Manually testing: Create a big hierarchy, like `<ListView>` example. Use the `TimerMixin` example to generate multiple calls.
Test the failure callback on the `Geolocation` example.
All the calls go through this entry point, so it's hard to miss if it's broken.
Summary:
@public
This removes the last piece of data that was still stored on the DATA section,
`RCT_IMPORT_METHOD`. JS calls now dynamically populate a lookup table simultaneously
on JS and Native, instead of creating a mapping at load time.
Test Plan: Everything still runs, tests are green.
Summary:
@public
I've increased the warning levels in the OSS frameworks, which caught a bunch of minor issues. I also fixed some new errors in Xcode 7 relating to designated initializers and TLS security.
Test Plan:
* Test the sample apps and make sure they still work.
* Run tests.
Summary:
@public
Include `js_name` and `__LINE__` on exported methods' generated names + use the
method implementation instead of `objc_msgSend` on the bridge, so it still works
in case of clashing.
Test Plan: Everything still working, otherwise it'd crash at startup.
Summary:
@public
The information we required about the exported methods were previously stored
on the binary's DATA section, which didn't allow to access methods on different
static libraries, or in any dynamic library at all. Instead of fetching information
from all the DATA segments, this diff changes the macro in order to create a
new method, that returns the required information about the original method. The
module itself is registered at load time, and on the bridge initialization all
the auto-generated methods are called to gather the methods' information.
Test Plan:
UIExplorer previously had a dependency on `RCTTest`, because it had a `TestModule`
that had to be on the same library. `RCTTest` is now a dependency of
`UIExplorerIntegrationTests`. So the tests themselves running should test it.
Summary:
@public
This is the first of a few diffs that change the way the executors are handled
by the bridge.
For they are just promoted to modules, so they are automatically loaded by the bridge.
Test Plan:
Tested on UIExplorer, Catalyst and MAdMan.
Tested all the 3 executors, everything looks fine.
Summary:
@public
`[Bridge] Add support for JS async functions to RCT_EXPORT_METHOD` was imported but broke some internal code, reverting the `MessageQueue` that caused the issues and add a test, since the method is not used yet.
Test Plan: Run the test o/
Summary:
Adds support for JS async methods and helps guide people writing native modules w.r.t. the callbacks. With this diff, on the native side you write:
```objc
RCT_EXPORT_METHOD(getValueAsync:(NSString *)key
resolver:(RCTPromiseResolver)resolve
rejecter:(RCTPromiseRejecter)reject)
{
NSError *error = nil;
id value = [_nativeDataStore valueForKey:key error:&error];
// "resolve" and "reject" are automatically defined blocks that take
// any object (nil is OK) and an NSError, respectively
if (!error) {
resolve(value);
} else {
reject(error);
}
}
```
On the JS side, you can write:
```js
var {DemoDataStore} = require('react-native').NativeModules;
DemoDataStore.getValueAsync('sample-key').then((value) => {
console.log('Got:', value);
}, (error) => {
console.error(error);
// "error" is an Error object whose message is the NSError's description.
// The NSError's code and domain are also set, and the native trace i
Closes https://github.com/facebook/react-native/pull/1232
Github Author: James Ide <ide@jameside.com>
Test Plan: Imported from GitHub, without a `Test Plan:` line.
Summary:
@public
For every call that comes from JS to Native we'd call dispatch_async so the
method would be cllead on the queue/thread it's expecting. This diff
buckets the calls by target queue, dispatches only once to that queue, and then
call all the methods for it inside the same dispatch.
Test Plan: {F22510090}
Summary:
@public
Bridge modules were being invalidate on the main thread, what could lead to
racing conditions, move the calls to invalidate on happen to the module's
methodQueue
Test Plan: Run the tests
Summary:
@public
Add `RCT_DEV`-only profiling hooks to every method in every bridge modules to
add a little bit more detail to the timeline profile.
Test Plan: {F22522834}
Summary:
Adds support for JS async methods and helps guide people writing native modules w.r.t. the callbacks. With this diff, on the native side you write:
```objc
RCT_EXPORT_METHOD(getValueAsync:(NSString *)key
resolver:(RCTPromiseResolver)resolve
rejecter:(RCTPromiseRejecter)reject)
{
NSError *error = nil;
id value = [_nativeDataStore valueForKey:key error:&error];
// "resolve" and "reject" are automatically defined blocks that take
// any object (nil is OK) and an NSError, respectively
if (!error) {
resolve(value);
} else {
reject(error);
}
}
```
On the JS side, you can write:
```js
var {DemoDataStore} = require('react-native').NativeModules;
DemoDataStore.getValueAsync('sample-key').then((value) => {
console.log('Got:', value);
}, (error) => {
console.error(error);
// "error" is an Error object whose message is the NSError's description.
// The NSError's code and domain are also set, and the native trace i
Closes https://github.com/facebook/react-native/pull/1232
Github Author: James Ide <ide@jameside.com>
Test Plan: Imported from GitHub, without a `Test Plan:` line.
Test plan: broke catalyst apps
Summary: This reverts commit 9fba6a360dc5f8bf.
fbobjc/Tools/revert
Reverter: jprado
@build-break
commit 9fba6a360dc5f8bf014f3d3c584c545b16da5100
Author: Tadeu Zagallo <tadeuzagallo@fb.com>
AuthorDate: Thu May 28 08:29:19 2015 -0700
Commit: Service User <svcscm@fb.com>
CommitDate: Thu May 28 09:53:53 2015 -0700
[ReactNative] Add completionBlock to -[RCTBridge enqueueJSCall:args:]
Summary:
@public
Allow to pass an optional completion block to the bridge JS calls.
The block will be called from the JS thread, after the javascript has finished
running and the returned calls have been processed/dispatched to the native modules.
Test Plan: Added `testCallbackIsCalledOnTheRightTime` to `RKBatchedBridgeTests`