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

@@ -1,7 +1,7 @@
/**
* Copyright 2004-present Facebook. All Rights Reserved.
*
* @providesModule Bundler
* @providesModule AppRegistry
*/
'use strict';
@@ -16,31 +16,42 @@ if (__DEV__) {
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) {
if (config[i].run) {
Bundler.registerRunnable(config[i].appKey, config[i].run);
AppRegistry.registerRunnable(config[i].appKey, config[i].run);
} 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] = {
run: (appParameters) =>
renderApplication(getComponentFunc(), appParameters.initialProps, appParameters.rootTag)
};
return appKey;
}
},
static registerRunnable(appKey, func) {
registerRunnable: function(appKey, func) {
runnables[appKey] = {run: func};
return appKey;
}
},
static runApplication(appKey, appParameters) {
runApplication: function(appKey, appParameters) {
console.log(
'Running application "' + appKey + '" with appParams: ',
appParameters
@@ -51,7 +62,7 @@ class Bundler {
'Application ' + appKey + ' has not been registered.'
);
runnables[appKey].run(appParameters);
}
}
},
};
module.exports = Bundler;
module.exports = AppRegistry;

View File

@@ -3,7 +3,7 @@ declare module "react-native" {
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 Image: ReactClass<any, any, any>;
declare var ListView: ReactClass<any, any, any>;

View File

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