react-native/Examples/UIExplorer/UIExplorerUnitTests
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
..
OCMock [ReactNative] Move unit tests to UIExplorer 2015-06-06 13:38:34 -08:00
Info.plist Increased warning levels to -Wall -Wextra, and fixed Xcode 7 beta issues 2015-06-15 07:52:50 -08:00
LayoutSubviewsOrderingTest.m Convert remaining uses of alloc] init] to new] 2015-11-02 08:03:17 -08:00
RCTAllocationTests.m [ReactNative] Increase timeout and re-enable allocation tests 2015-09-01 08:53:47 -08:00
RCTBridgeTests.m Replaced RCTSparseArray with NSDictionary 2015-11-14 10:28:28 -08:00
RCTContextExecutorTests.m Use JSStringCreateWithUTF8CString and skip NSString decoding when loading the bundle 2015-10-16 08:11:25 -07:00
RCTConvert_NSURLTests.m Use mainBundle in RCTConvert to resolve asset paths 2015-11-05 09:30:36 -08:00
RCTConvert_UIFontTests.m Implemented lazy parsing of method signatures to improve TTI 2015-08-11 08:49:13 -08:00
RCTEventDispatcherTests.m Refactored module access to allow for lazy loading 2015-11-25 04:49:45 -08:00
RCTGzipTests.m Refactored module access to allow for lazy loading 2015-11-25 04:49:45 -08:00
RCTImageLoaderHelpers.h Added RCTDataRequestHandler 2015-10-19 09:07:06 -07:00
RCTImageLoaderHelpers.m Added RCTDataRequestHandler 2015-10-19 09:07:06 -07:00
RCTImageLoaderTests.m Added RCTDataRequestHandler 2015-10-19 09:07:06 -07:00
RCTImageUtilTests.m Fixed image clipping / resizing logic 2015-08-13 08:13:55 -08:00
RCTJSONTests.m Replaced RCTSparseArray with NSDictionary 2015-11-14 10:28:28 -08:00
RCTMethodArgumentTests.m NSNumber arguments must now be nonnull 2015-07-31 06:57:08 -08:00
RCTModuleMethodTests.m Provide log source to handler 2015-11-11 06:44:30 -08:00
RCTShadowViewTests.m Return viewsWithNewFrame instead of passing it around 2015-11-17 06:37:31 -08:00
RCTUIManagerTests.m Replaced RCTSparseArray with NSDictionary 2015-11-14 10:28:28 -08:00
libOCMock.a [ReactNative] Move unit tests to UIExplorer 2015-06-06 13:38:34 -08:00