react-native/Libraries
Nick Lockwood 060664fd3d Refactored module access to allow for lazy loading
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
2015-11-25 04:49:45 -08:00
..
ART Mark `-[init]` w RCT_NOT_IMPLEMENTED 2015-11-14 06:29:27 -08:00
ActionSheetIOS Added Subject to ActionSheetIOS share options and updated example 2015-11-19 08:42:31 -08:00
AdSupport Text highlighting on iOS 2015-07-24 08:41:58 -08:00
Animated Fixed Typo 2015-11-18 08:10:30 -08:00
AppRegistry [React Native] Provide a way to get a list of registered apps in AppRegistry 2015-08-07 11:05:25 -08:00
AppStateIOS revert D2372548 to fix initial app state issue 2015-09-25 13:25:26 -07:00
BatchedBridge Adding jest tests to groups rn 2015-08-31 17:35:47 -08:00
CameraRoll Refactored module access to allow for lazy loading 2015-11-25 04:49:45 -08:00
Components Remove scrollview support from UIManager, remove mainScrollView(delegate) 2015-11-25 04:12:34 -08:00
CustomComponents Fix move gesture handling. 2015-11-23 09:20:28 -08:00
DebugComponentHierarchy [ReactNative] Send debug component ownership info in createView 2015-06-25 05:47:24 -08:00
Device
Devtools Use pre-bundled elements inspector 2015-10-29 11:21:32 -07:00
Fetch Add fetch's clone function to Request and Response prototypes 2015-10-30 10:57:33 -07:00
Geolocation Refactored module access to allow for lazy loading 2015-11-25 04:49:45 -08:00
Image Refactored module access to allow for lazy loading 2015-11-25 04:49:45 -08:00
Inspector [react-native] enable react devtools from JavascriptCore 2015-07-23 17:14:09 -08:00
Interaction Make InteractionManager.runAfterInteractions() return a Promise 2015-11-09 20:14:26 -08:00
JavaScriptAppEngine Move RelayProfiler Decoupled Initialization to use Double Dispatch 2015-11-23 19:24:27 -08:00
LayoutAnimation [ReactNative] Remove POPAnimation 2015-08-20 22:24:28 -07:00
LinkingIOS Refactored module access to allow for lazy loading 2015-11-25 04:49:45 -08:00
Modal Make <Modal> visible by default 2015-10-30 17:09:27 -07:00
NativeApp [ReactNative] Add "RCTNativeAppEventEmitter" 2015-05-15 16:57:18 -08:00
Network Refactored module access to allow for lazy loading 2015-11-25 04:49:45 -08:00
Picker Compose propTypes from View.propTypes where appropriate. 2015-11-18 13:06:27 -08:00
Portal [RN] add clarifying Android-only comment to Portal 2015-08-31 11:10:45 -08:00
PullToRefresh Open source SwipeRefreshLayoutAndroid 2015-11-24 10:15:14 -08:00
PushNotificationIOS Refactored module access to allow for lazy loading 2015-11-25 04:49:45 -08:00
QuickPerformanceLogger added QPL for main interactions 2015-09-29 22:25:23 -07:00
RCTTest Refactored module access to allow for lazy loading 2015-11-25 04:49:45 -08:00
RKBackendNode [ReactNative] clean lint in all of Libraries/ 2015-05-19 13:47:04 -08:00
ReactIOS RN: Add "Dismiss All" to YellowBox 2015-11-24 11:37:31 -08:00
ReactNative Defer rendering events popover until required 2015-11-25 04:15:27 -08:00
Sample Remove invariant of Sample.ios.js that is not used 2015-05-26 18:25:00 -07:00
Settings Refactored module access to allow for lazy loading 2015-11-25 04:49:45 -08:00
Storage Implement efficient DiskCache.clear() 2015-11-25 03:23:36 -08:00
StyleSheet enable the minWidth/maxWidth/minHeight/maxHeight features 2015-11-17 10:58:32 -08:00
Text Fix flaky scrolling for TextInput when using rich text 2015-11-24 15:38:27 -08:00
Utilities Fix logging JSAppRequireTime 2015-11-24 10:20:28 -08:00
Vibration Text highlighting on iOS 2015-07-24 08:41:58 -08:00
WebSocket Refactored module access to allow for lazy loading 2015-11-25 04:49:45 -08:00
react-native Open source SwipeRefreshLayoutAndroid 2015-11-24 10:15:14 -08:00
vendor send fatal error for js exception in eventEmitter 2015-11-23 13:52:27 -08:00
Promise.js