Enabled pretier (@format) for all files in ReactNative folder

Reviewed By: mmmulani

Differential Revision: D5894100

fbshipit-source-id: fae0d02547c0f049fc77f87f209b2ae4f2a298fd
This commit is contained in:
Valentin Shergin
2017-09-24 22:57:35 -07:00
committed by Facebook Github Bot
parent 7e5d4335ca
commit 8606e04c5d
9 changed files with 211 additions and 147 deletions

View File

@@ -8,6 +8,7 @@
*
* @providesModule AppRegistry
* @flow
* @format
*/
'use strict';
@@ -24,8 +25,9 @@ const renderApplication = require('renderApplication');
type Task = (taskData: any) => Promise<void>;
type TaskProvider = () => Task;
export type ComponentProvider = () => React$ComponentType<any>;
export type ComponentProviderInstrumentationHook =
(component: ComponentProvider) => React$ComponentType<any>;
export type ComponentProviderInstrumentationHook = (
component: ComponentProvider,
) => React$ComponentType<any>;
export type AppConfig = {
appKey: string,
component?: ComponentProvider,
@@ -49,8 +51,9 @@ const runnables: Runnables = {};
let runCount = 1;
const sections: Runnables = {};
const tasks: Map<string, TaskProvider> = new Map();
let componentProviderInstrumentationHook: ComponentProviderInstrumentationHook =
(component: ComponentProvider) => component();
let componentProviderInstrumentationHook: ComponentProviderInstrumentationHook = (
component: ComponentProvider,
) => component();
let wrapperComponentProvider: ?WrapperComponentProvider;
@@ -86,15 +89,15 @@ const AppRegistry = {
},
registerConfig(config: Array<AppConfig>): void {
config.forEach((appConfig) => {
config.forEach(appConfig => {
if (appConfig.run) {
AppRegistry.registerRunnable(appConfig.appKey, appConfig.run);
} else {
invariant(
appConfig.component != null,
'AppRegistry.registerConfig(...): Every config is expected to set ' +
'either `run` or `component`, but `%s` has neither.',
appConfig.appKey
'either `run` or `component`, but `%s` has neither.',
appConfig.appKey,
);
AppRegistry.registerComponent(
appConfig.appKey,
@@ -112,13 +115,13 @@ const AppRegistry = {
): string {
runnables[appKey] = {
componentProvider,
run: (appParameters) =>
run: appParameters =>
renderApplication(
componentProviderInstrumentationHook(componentProvider),
appParameters.initialProps,
appParameters.rootTag,
wrapperComponentProvider && wrapperComponentProvider(appParameters),
)
),
};
if (section) {
sections[appKey] = runnables[appKey];
@@ -145,7 +148,7 @@ const AppRegistry = {
getSections(): Runnables {
return {
...sections
...sections,
};
},
@@ -160,31 +163,44 @@ const AppRegistry = {
};
},
setComponentProviderInstrumentationHook(hook: ComponentProviderInstrumentationHook) {
setComponentProviderInstrumentationHook(
hook: ComponentProviderInstrumentationHook,
) {
componentProviderInstrumentationHook = hook;
},
runApplication(appKey: string, appParameters: any): void {
const msg =
'Running application "' + appKey + '" with appParams: ' +
JSON.stringify(appParameters) + '. ' +
'__DEV__ === ' + String(__DEV__) +
', development-level warning are ' + (__DEV__ ? 'ON' : 'OFF') +
', performance optimizations are ' + (__DEV__ ? 'OFF' : 'ON');
'Running application "' +
appKey +
'" with appParams: ' +
JSON.stringify(appParameters) +
'. ' +
'__DEV__ === ' +
String(__DEV__) +
', development-level warning are ' +
(__DEV__ ? 'ON' : 'OFF') +
', performance optimizations are ' +
(__DEV__ ? 'OFF' : 'ON');
infoLog(msg);
BugReporting.addSource('AppRegistry.runApplication' + runCount++, () => msg);
BugReporting.addSource(
'AppRegistry.runApplication' + runCount++,
() => msg,
);
invariant(
runnables[appKey] && runnables[appKey].run,
'Application ' + appKey + ' has not been registered.\n\n' +
'Hint: This error often happens when you\'re running the packager ' +
'(local dev server) from a wrong folder. For example you have ' +
'multiple apps and the packager is still running for the app you ' +
'were working on before.\nIf this is the case, simply kill the old ' +
'packager instance (e.g. close the packager terminal window) ' +
'and start the packager in the correct app folder (e.g. cd into app ' +
'folder and run \'npm start\').\n\n' +
'This error can also happen due to a require() error during ' +
'initialization or failure to call AppRegistry.registerComponent.\n\n'
'Application ' +
appKey +
' has not been registered.\n\n' +
"Hint: This error often happens when you're running the packager " +
'(local dev server) from a wrong folder. For example you have ' +
'multiple apps and the packager is still running for the app you ' +
'were working on before.\nIf this is the case, simply kill the old ' +
'packager instance (e.g. close the packager terminal window) ' +
'and start the packager in the correct app folder (e.g. cd into app ' +
"folder and run 'npm start').\n\n" +
'This error can also happen due to a require() error during ' +
'initialization or failure to call AppRegistry.registerComponent.\n\n',
);
SceneTracker.setActiveScene({name: appKey});
@@ -204,7 +220,9 @@ const AppRegistry = {
*/
registerHeadlessTask(taskKey: string, task: TaskProvider): void {
if (tasks.has(taskKey)) {
console.warn(`registerHeadlessTask called multiple times for same key '${taskKey}'`);
console.warn(
`registerHeadlessTask called multiple times for same key '${taskKey}'`,
);
}
tasks.set(taskKey, task);
},
@@ -222,18 +240,16 @@ const AppRegistry = {
throw new Error(`No task registered for key ${taskKey}`);
}
taskProvider()(data)
.then(() => NativeModules.HeadlessJsTaskSupport.notifyTaskFinished(taskId))
.then(() =>
NativeModules.HeadlessJsTaskSupport.notifyTaskFinished(taskId),
)
.catch(reason => {
console.error(reason);
NativeModules.HeadlessJsTaskSupport.notifyTaskFinished(taskId);
});
}
},
};
BatchedBridge.registerCallableModule(
'AppRegistry',
AppRegistry
);
BatchedBridge.registerCallableModule('AppRegistry', AppRegistry);
module.exports = AppRegistry;