react-native/React/Base
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
..
RCTAssert.h Reduced work done on main thread by RCTImageLoader 2015-11-17 07:21:29 -08:00
RCTAssert.m Add exception description to exception name 2015-11-23 16:19:29 -08:00
RCTBatchedBridge.m Refactored module access to allow for lazy loading 2015-11-25 04:49:45 -08:00
RCTBridge.h Refactored module access to allow for lazy loading 2015-11-25 04:49:45 -08:00
RCTBridge.m Refactored module access to allow for lazy loading 2015-11-25 04:49:45 -08:00
RCTBridgeDelegate.h Added headerdoc for RCTBridgeDelegate 2015-11-06 05:28:33 -08:00
RCTBridgeMethod.h Prepare the bridge for C++ 2015-09-18 15:04:28 -07:00
RCTBridgeModule.h Refactored module access to allow for lazy loading 2015-11-25 04:49:45 -08:00
RCTConvert.h Add keyboardAppearance prop to TextInput component. 2015-11-11 05:38:35 -08:00
RCTConvert.m Removed all calls to [UIImage imageWithData:] on a background thread 2015-11-20 05:17:33 -08:00
RCTDefines.h Implement asm trampoline rather forwardInvocation 2015-10-20 04:14:09 -07:00
RCTEventDispatcher.h Implements `onKeyPress` 2015-11-02 09:15:31 -08:00
RCTEventDispatcher.m Refactored module access to allow for lazy loading 2015-11-25 04:49:45 -08:00
RCTFrameUpdate.h Pause JS DisplayLink if nothing to process. 2015-09-29 09:22:10 -07:00
RCTFrameUpdate.m Ran Convert > To Modern Objective C Syntax 2015-08-25 01:08:49 -08:00
RCTInvalidating.h Remove isValid from RCTInvalidating 2015-08-14 01:57:18 -08:00
RCTJSMethodRegistrar.h Added non-class-scanning-based approach fror registering js methods 2015-04-08 05:45:20 -08:00
RCTJavaScriptExecutor.h Use JSStringCreateWithUTF8CString and skip NSString decoding when loading the bundle 2015-10-16 08:11:25 -07:00
RCTJavaScriptLoader.h [ReactNative] Add RCTBridgeDelegate 2015-07-28 15:57:02 -08:00
RCTJavaScriptLoader.m Added lightweight generic annotations 2015-11-03 14:49:30 -08:00
RCTKeyCommands.h Updates from Thu 26 Mar 2015-03-26 06:32:01 -07:00
RCTKeyCommands.m Added lightweight generic annotations 2015-11-03 14:49:30 -08:00
RCTKeyboardObserver.h Add keyboard-observing notifications 2015-08-25 03:49:13 -08:00
RCTKeyboardObserver.m Refactored module access to allow for lazy loading 2015-11-25 04:49:45 -08:00
RCTLog.h Provide log source to handler 2015-11-11 06:44:30 -08:00
RCTLog.m Replaced RCTSparseArray with NSDictionary 2015-11-14 10:28:28 -08:00
RCTModuleData.h Refactored module access to allow for lazy loading 2015-11-25 04:49:45 -08:00
RCTModuleData.m Refactored module access to allow for lazy loading 2015-11-25 04:49:45 -08:00
RCTModuleMethod.h Bring back D2570057 (previously backed out) + fixes 2015-10-28 18:44:26 -07:00
RCTModuleMethod.m Added lightweight generic annotations 2015-11-03 14:49:30 -08:00
RCTPerformanceLogger.h Added lightweight generic annotations 2015-11-03 14:49:30 -08:00
RCTPerformanceLogger.m Refactored module access to allow for lazy loading 2015-11-25 04:49:45 -08:00
RCTRootView.h Props setter for RCTRootView 2015-10-30 09:28:27 -07:00
RCTRootView.m Prevent RCTRootView delegate call 2015-11-13 08:28:28 -08:00
RCTRootViewDelegate.h Prevent RCTRootView delegate call 2015-11-13 08:28:28 -08:00
RCTRootViewInternal.h Introduction of RCTRootViewDelegate 2015-10-26 15:41:36 -07:00
RCTTouchHandler.h [ReactNative] Send batched calls from objc to js every frame + add bridge profiling 2015-04-17 04:01:02 -08:00
RCTTouchHandler.m Added lightweight generic annotations 2015-11-03 14:49:30 -08:00
RCTURLRequestDelegate.h Refactored networking logic out into RCTDownloadTask 2015-07-23 04:00:31 -08:00
RCTURLRequestHandler.h [ReactNative] Refactor RCTDataManager to support pluggable data source modules (RCTURLRequestHandlers) 2015-06-09 12:27:06 -08:00
RCTUtils.h Refactored module access to allow for lazy loading 2015-11-25 04:49:45 -08:00
RCTUtils.m Refactored module access to allow for lazy loading 2015-11-25 04:49:45 -08:00