From c6e2b584afbd936611a86b1015fef0f9c97ec178 Mon Sep 17 00:00:00 2001 From: Nicolas Gallagher Date: Sat, 21 Apr 2018 12:05:42 -0700 Subject: [PATCH] [fix] AppRegistry.getApplication shouldn't throw if missing options Fix #899 --- .../src/exports/AppRegistry/__tests__/index-test.js | 5 +++++ packages/react-native-web/src/exports/AppRegistry/index.js | 4 ++-- website/storybook/2-apis/AppRegistry/AppRegistryScreen.js | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/react-native-web/src/exports/AppRegistry/__tests__/index-test.js b/packages/react-native-web/src/exports/AppRegistry/__tests__/index-test.js index f059f7fa..cab2ebdf 100644 --- a/packages/react-native-web/src/exports/AppRegistry/__tests__/index-test.js +++ b/packages/react-native-web/src/exports/AppRegistry/__tests__/index-test.js @@ -22,6 +22,11 @@ describe('AppRegistry', () => { ExecutionEnvironment.canUseDOM = canUseDOM; }); + test('does not throw when missing appParameters', () => { + AppRegistry.registerComponent('App', () => RootComponent); + expect(() => AppRegistry.getApplication('App')).not.toThrow(); + }); + test('returns "element" and "getStyleElement"', () => { AppRegistry.registerComponent('App', () => RootComponent); diff --git a/packages/react-native-web/src/exports/AppRegistry/index.js b/packages/react-native-web/src/exports/AppRegistry/index.js index 3804c1c3..a5f19fff 100644 --- a/packages/react-native-web/src/exports/AppRegistry/index.js +++ b/packages/react-native-web/src/exports/AppRegistry/index.js @@ -58,7 +58,7 @@ export default class AppRegistry { getApplication: appParameters => getApplication( componentProviderInstrumentationHook(componentProvider), - appParameters.initialProps || emptyObject, + appParameters ? appParameters.initialProps : emptyObject, wrapperComponentProvider && wrapperComponentProvider(appParameters) ), run: appParameters => @@ -90,7 +90,7 @@ export default class AppRegistry { return appKey; } - static runApplication(appKey: string, appParameters?: Object): void { + static runApplication(appKey: string, appParameters: Object): void { const isDevelopment = process.env.NODE_ENV !== 'production'; const params = { ...appParameters }; params.rootTag = `#${params.rootTag.id}`; diff --git a/website/storybook/2-apis/AppRegistry/AppRegistryScreen.js b/website/storybook/2-apis/AppRegistry/AppRegistryScreen.js index e8496d19..3abff5ef 100644 --- a/website/storybook/2-apis/AppRegistry/AppRegistryScreen.js +++ b/website/storybook/2-apis/AppRegistry/AppRegistryScreen.js @@ -93,7 +93,7 @@ const AppRegistryScreen = () => ( })` }} name="static runApplication" - typeInfo="(appKey: string, appParameters?: object) => void" + typeInfo="(appKey: string, appParameters: object) => void" />