2015-01-30 01:10:49 +00:00
|
|
|
/**
|
|
|
|
* Copyright 2004-present Facebook. All Rights Reserved.
|
|
|
|
*
|
2015-02-19 14:57:05 +00:00
|
|
|
* @providesModule AppRegistry
|
2015-01-30 01:10:49 +00:00
|
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var invariant = require('invariant');
|
|
|
|
var renderApplication = require('renderApplication');
|
|
|
|
|
|
|
|
if (__DEV__) {
|
|
|
|
// In order to use Cmd+P to record/dump perf data, we need to make sure
|
|
|
|
// this module is available in the bundle
|
|
|
|
require('RCTRenderingPerf');
|
|
|
|
}
|
|
|
|
|
|
|
|
var runnables = {};
|
|
|
|
|
2015-02-19 14:57:05 +00:00
|
|
|
/**
|
|
|
|
* `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) {
|
2015-01-30 01:10:49 +00:00
|
|
|
for (var i = 0; i < config.length; ++i) {
|
|
|
|
if (config[i].run) {
|
2015-02-19 14:57:05 +00:00
|
|
|
AppRegistry.registerRunnable(config[i].appKey, config[i].run);
|
2015-01-30 01:10:49 +00:00
|
|
|
} else {
|
2015-02-19 14:57:05 +00:00
|
|
|
AppRegistry.registerComponent(config[i].appKey, config[i].component);
|
2015-01-30 01:10:49 +00:00
|
|
|
}
|
|
|
|
}
|
2015-02-19 14:57:05 +00:00
|
|
|
},
|
2015-01-30 01:10:49 +00:00
|
|
|
|
2015-02-19 14:57:05 +00:00
|
|
|
registerComponent: function(appKey, getComponentFunc) {
|
2015-01-30 01:10:49 +00:00
|
|
|
runnables[appKey] = {
|
|
|
|
run: (appParameters) =>
|
|
|
|
renderApplication(getComponentFunc(), appParameters.initialProps, appParameters.rootTag)
|
|
|
|
};
|
|
|
|
return appKey;
|
2015-02-19 14:57:05 +00:00
|
|
|
},
|
2015-01-30 01:10:49 +00:00
|
|
|
|
2015-02-19 14:57:05 +00:00
|
|
|
registerRunnable: function(appKey, func) {
|
2015-01-30 01:10:49 +00:00
|
|
|
runnables[appKey] = {run: func};
|
|
|
|
return appKey;
|
2015-02-19 14:57:05 +00:00
|
|
|
},
|
2015-01-30 01:10:49 +00:00
|
|
|
|
2015-02-19 14:57:05 +00:00
|
|
|
runApplication: function(appKey, appParameters) {
|
2015-01-30 01:10:49 +00:00
|
|
|
console.log(
|
2015-03-11 02:11:28 +00:00
|
|
|
'Running application "' + appKey + '" with appParams: ' +
|
|
|
|
JSON.stringify(appParameters) + '. ' +
|
|
|
|
'__DEV__ === ' + __DEV__ +
|
|
|
|
', development-level warning are ' + (__DEV__ ? 'ON' : 'OFF') +
|
|
|
|
', performance optimizations are ' + (__DEV__ ? 'OFF' : 'ON')
|
2015-01-30 01:10:49 +00:00
|
|
|
);
|
|
|
|
invariant(
|
|
|
|
runnables[appKey] && runnables[appKey].run,
|
|
|
|
'Application ' + appKey + ' has not been registered.'
|
|
|
|
);
|
|
|
|
runnables[appKey].run(appParameters);
|
2015-02-19 14:57:05 +00:00
|
|
|
},
|
|
|
|
};
|
2015-01-30 01:10:49 +00:00
|
|
|
|
2015-02-19 14:57:05 +00:00
|
|
|
module.exports = AppRegistry;
|