Updates from Feb 19

- [Catalyst] Clean up bundling/runApp to match OSS | Spencer Ahrens
- [react-native][pull request] Add root to packager via cli | Boopathi Rajaa | Amjad Masad
This commit is contained in:
Spencer Ahrens 2015-02-19 06:57:05 -08:00
parent 8f68996ccd
commit 3abf4fb6ae
10 changed files with 132 additions and 121 deletions

View File

@ -8,7 +8,7 @@
var React = require('react-native/addons'); var React = require('react-native/addons');
var { var {
Bundler, AppRegistry,
NavigatorIOS, NavigatorIOS,
StyleSheet, StyleSheet,
} = React; } = React;
@ -36,6 +36,6 @@ var styles = StyleSheet.create({
}, },
}); });
Bundler.registerComponent('MoviesApp', () => MoviesApp); AppRegistry.registerComponent('MoviesApp', () => MoviesApp);
module.exports = MoviesApp; module.exports = MoviesApp;

View File

@ -8,7 +8,7 @@
var React = require('react-native'); var React = require('react-native');
var { var {
Bundler, AppRegistry,
Image, Image,
StyleSheet, StyleSheet,
Text, Text,
@ -317,6 +317,6 @@ var styles = StyleSheet.create({
}, },
}); });
Bundler.registerComponent('TicTacToeApp', () => TicTacToeApp); AppRegistry.registerComponent('TicTacToeApp', () => TicTacToeApp);
module.exports = TicTacToeApp; module.exports = TicTacToeApp;

View File

@ -9,7 +9,7 @@ var React = require('react-native/addons');
var UIExplorerList = require('./UIExplorerList'); var UIExplorerList = require('./UIExplorerList');
var { var {
Bundler, AppRegistry,
NavigatorIOS, NavigatorIOS,
StyleSheet, StyleSheet,
} = React; } = React;
@ -39,6 +39,6 @@ var styles = StyleSheet.create({
}, },
}); });
Bundler.registerComponent('UIExplorerApp', () => UIExplorerApp); AppRegistry.registerComponent('UIExplorerApp', () => UIExplorerApp);
module.exports = UIExplorerApp; module.exports = UIExplorerApp;

View File

@ -1,7 +1,7 @@
/** /**
* Copyright 2004-present Facebook. All Rights Reserved. * Copyright 2004-present Facebook. All Rights Reserved.
* *
* @providesModule Bundler * @providesModule AppRegistry
*/ */
'use strict'; 'use strict';
@ -16,31 +16,42 @@ if (__DEV__) {
var runnables = {}; var runnables = {};
class Bundler { /**
static registerConfig(config) { * `AppRegistry` is the JS entry point to running all React Native apps. App
* root components should register themselves with
* `AppRegistry.registerComponent`, then the native system can load the bundle
* for the app and then actually run the app when it's ready by invoking
* `AppRegistry.runApplication`.
*
* `AppRegistry` should be `require`d early in the `require` sequence to make
* sure the JS execution environment is setup before other modules are
* `require`d.
*/
var AppRegistry = {
registerConfig: function(config) {
for (var i = 0; i < config.length; ++i) { for (var i = 0; i < config.length; ++i) {
if (config[i].run) { if (config[i].run) {
Bundler.registerRunnable(config[i].appKey, config[i].run); AppRegistry.registerRunnable(config[i].appKey, config[i].run);
} else { } else {
Bundler.registerComponent(config[i].appKey, config[i].component); AppRegistry.registerComponent(config[i].appKey, config[i].component);
} }
} }
} },
static registerComponent(appKey, getComponentFunc) { registerComponent: function(appKey, getComponentFunc) {
runnables[appKey] = { runnables[appKey] = {
run: (appParameters) => run: (appParameters) =>
renderApplication(getComponentFunc(), appParameters.initialProps, appParameters.rootTag) renderApplication(getComponentFunc(), appParameters.initialProps, appParameters.rootTag)
}; };
return appKey; return appKey;
} },
static registerRunnable(appKey, func) { registerRunnable: function(appKey, func) {
runnables[appKey] = {run: func}; runnables[appKey] = {run: func};
return appKey; return appKey;
} },
static runApplication(appKey, appParameters) { runApplication: function(appKey, appParameters) {
console.log( console.log(
'Running application "' + appKey + '" with appParams: ', 'Running application "' + appKey + '" with appParams: ',
appParameters appParameters
@ -51,7 +62,7 @@ class Bundler {
'Application ' + appKey + ' has not been registered.' 'Application ' + appKey + ' has not been registered.'
); );
runnables[appKey].run(appParameters); runnables[appKey].run(appParameters);
} },
} };
module.exports = Bundler; module.exports = AppRegistry;

View File

@ -3,7 +3,7 @@ declare module "react-native" {
constructor(params: Object): void; constructor(params: Object): void;
} }
declare var Bundler: ReactClass<any, any, any>; declare var AppRegistry: ReactClass<any, any, any>;
declare var ExpandingText: ReactClass<any, any, any>; declare var ExpandingText: ReactClass<any, any, any>;
declare var Image: ReactClass<any, any, any>; declare var Image: ReactClass<any, any, any>;
declare var ListView: ReactClass<any, any, any>; declare var ListView: ReactClass<any, any, any>;

View File

@ -7,7 +7,7 @@
var ReactNative = { var ReactNative = {
...require('React'), ...require('React'),
Bundler: require('Bundler'), AppRegistry: require('AppRegistry'),
ExpandingText: require('ExpandingText'), ExpandingText: require('ExpandingText'),
Image: require('Image'), Image: require('Image'),
LayoutAnimation: require('LayoutAnimation'), LayoutAnimation: require('LayoutAnimation'),

View File

@ -109,7 +109,7 @@ well :)
A. Copy the entire `Examples/TicTacToe` folder, rename stuff in Xcode, and A. Copy the entire `Examples/TicTacToe` folder, rename stuff in Xcode, and
replace the `TicTacToeApp.js` with your own. Then, in `AppDelegate.m`, update replace the `TicTacToeApp.js` with your own. Then, in `AppDelegate.m`, update
`moduleName` to match your call to `moduleName` to match your call to
`Bundler.registerComponent(<moduleName>, <componentName>)` at the bottom of your `AppRegistry.registerComponent(<moduleName>, <componentName>)` at the bottom of your
JS file, and update `jsCodeLocation` to match your JS file name and location. JS file, and update `jsCodeLocation` to match your JS file name and location.
##### Q. Can I submit my own React Native app to the App Store? ##### Q. Can I submit my own React Native app to the App Store?

View File

@ -305,7 +305,7 @@ static NSDictionary *RCTLocalModulesConfig()
// Add globally used methods // Add globally used methods
[JSMethods addObjectsFromArray:@[ [JSMethods addObjectsFromArray:@[
@"Bundler.runApplication", @"AppRegistry.runApplication",
@"RCTDeviceEventEmitter.emit", @"RCTDeviceEventEmitter.emit",
@"RCTEventEmitter.receiveEvent", @"RCTEventEmitter.receiveEvent",
@"RCTEventEmitter.receiveTouches", @"RCTEventEmitter.receiveTouches",

View File

@ -104,7 +104,7 @@ static Class _globalExecutorClass;
@"rootTag": self.reactTag, @"rootTag": self.reactTag,
@"initialProps": self.initialProperties ?: @{}, @"initialProps": self.initialProperties ?: @{},
}; };
[_bridge enqueueJSCall:@"Bundler.runApplication" [_bridge enqueueJSCall:@"AppRegistry.runApplication"
args:@[moduleName, appParameters]]; args:@[moduleName, appParameters]];
} }
} }

View File

@ -35,7 +35,7 @@ static JSValueRef RCTNativeLoggingHook(JSContextRef context, JSObjectRef object,
NSString *str = (__bridge_transfer NSString *)JSStringCopyCFString(kCFAllocatorDefault, string); NSString *str = (__bridge_transfer NSString *)JSStringCopyCFString(kCFAllocatorDefault, string);
NSError *error = nil; NSError *error = nil;
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern: NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:
@"( stack: )?([_a-z0-9]*)@?(http://|file:///)[a-z.0-9:/_-]+/MainBundle/([a-z0-9_]+).includeRequire.runModule.bundle(:[0-9]+:[0-9]+)" @"( stack: )?([_a-z0-9]*)@?(http://|file:///)[a-z.0-9:/_-]+/([a-z0-9_]+).includeRequire.runModule.bundle(:[0-9]+:[0-9]+)"
options:NSRegularExpressionCaseInsensitive options:NSRegularExpressionCaseInsensitive
error:&error]; error:&error];
NSString *modifiedString = [regex stringByReplacingMatchesInString:str options:0 range:NSMakeRange(0, [str length]) withTemplate:@"[$4$5] \t$2"]; NSString *modifiedString = [regex stringByReplacingMatchesInString:str options:0 range:NSMakeRange(0, [str length]) withTemplate:@"[$4$5] \t$2"];