react-native/Libraries/Utilities
Sebastian Markbage 8d397b4cbc Decouple Module System from Native Calls
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
2015-12-08 16:03:37 -08:00
..
__mocks__ [ReactNative] clean lint in all of Libraries/ 2015-05-19 13:47:04 -08:00
__tests__ Decouple Module System from Native Calls 2015-12-08 16:03:37 -08:00
differ [ReactNative] Fix warnings w/h => width/height 2015-05-02 10:22:59 -08:00
AlertIOS.js Add secure and login-password types to AlertIOS. 2015-11-30 19:51:41 -08:00
BackAndroid.android.js add docs to BackAndroid so they show up in the website 2015-09-17 17:20:32 -07:00
BackAndroid.ios.js RN: Remove BackAndroid Warning 2015-11-12 13:24:27 -08:00
BridgeProfiling.js Fix systrace profile handling for relay async calls 2015-12-01 08:42:24 -08:00
CPUProfiler.js Add NativeProfiling module that uses RN nativeProfiler or console.profile 2015-11-27 04:44:25 -08:00
CSSVarConfig.js [ReactNative] OSS JSNavigationStack w/ Examples 2015-03-24 09:39:40 -08:00
Dimensions.js Wrapped UIManager native module for better abstraction 2015-11-27 07:00:32 -08:00
ErrorUtils.js [Cosmetic] Fixing comment typo 2015-06-02 20:23:34 -08:00
MatrixMath.js Fix errors uncovered by v0.19.0 2015-12-01 20:11:26 -08:00
MessageQueue.js Decouple Module System from Native Calls 2015-12-08 16:03:37 -08:00
PerformanceLogger.js Decouple Module System from Native Calls 2015-12-08 16:03:37 -08:00
PixelRatio.js [ReactNative] PixelRatio docs 2015-07-27 09:40:08 -08:00
Platform.android.js Release React Native for Android 2015-09-14 18:13:39 +01:00
Platform.ios.js Flowify Library/Utilities/ 2015-03-23 16:47:26 -08:00
RCTLog.js Decouple Module System from Native Calls 2015-12-08 16:03:37 -08:00
RCTRenderingPerf.js [ReactNative] clean lint in all of Libraries/ 2015-05-19 13:47:04 -08:00
UIManager.js Wrapped UIManager native module for better abstraction 2015-11-27 07:00:32 -08:00
buildStyleInterpolator.js Make Style Interpolator Function Generation Lazy 2015-11-23 14:20:29 -08:00
createStrictShapeTypeChecker.js fix library/utility lint warnings 2015-11-30 16:15:30 -08:00
cssVar.js [ReactNative] OSS JSNavigationStack w/ Examples 2015-03-24 09:39:40 -08:00
deepFreezeAndThrowOnMutationInDev.js Flowify Library/Utilities/ 2015-03-23 16:47:26 -08:00
dismissKeyboard.js [ReactNative] Sync [react_native] Fix keyboard behavior for android 2015-08-14 02:58:37 -08:00
groupByEveryN.js Flowify Library/Utilities/ 2015-03-23 16:47:26 -08:00
logError.js Flowify Library/Utilities/ 2015-03-23 16:47:26 -08:00
mapWithSeparator.js select up and down the inspector hierarchy 2015-06-04 10:18:56 -08:00
mergeFast.js Fix typo 2015-08-06 20:22:24 -08:00
mergeIntoFast.js Flowify Library/Utilities/ 2015-03-23 16:47:26 -08:00
nativeModulePrefixNormalizer.js Flowify Library/Utilities/ 2015-03-23 16:47:26 -08:00
stringifySafe.js [ReactNative] improve console logging a little bit 2015-05-04 18:57:03 -08:00
truncate.js [ReactNative] clean lint in all of Libraries/ 2015-05-19 13:47:04 -08:00