mirror of
https://github.com/status-im/react-navigation.git
synced 2025-02-25 01:28:16 +00:00
* remove ineffective invariant usages * fix flow err * fix tests * fix tests * use throw
This commit is contained in:
parent
c08be7fb43
commit
e4a7b7e073
@ -1,7 +1,6 @@
|
||||
/* @flow */
|
||||
|
||||
import React from 'react';
|
||||
import invariant from './utils/invariant';
|
||||
import { BackHandler, Linking } from './PlatformHelpers';
|
||||
import NavigationActions from './NavigationActions';
|
||||
import addNavigationHelpers from './addNavigationHelpers';
|
||||
@ -74,8 +73,8 @@ export default function createNavigationContainer<S: *, O>(
|
||||
|
||||
const keys = Object.keys(containerProps);
|
||||
|
||||
invariant(
|
||||
keys.length === 0,
|
||||
if (keys.length !== 0) {
|
||||
throw new Error(
|
||||
'This navigator has both navigation and container props, so it is ' +
|
||||
`unclear if it should own its own state. Remove props: "${keys.join(
|
||||
', '
|
||||
@ -84,6 +83,7 @@ export default function createNavigationContainer<S: *, O>(
|
||||
'navigator should maintain its own state, do not pass a navigation prop.'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
_urlToPathAndParams(url: string) {
|
||||
const params = {};
|
||||
|
@ -45,11 +45,12 @@ export default (
|
||||
tabRouters[routeName] = routeConfig.screen.router;
|
||||
}
|
||||
});
|
||||
invariant(
|
||||
initialRouteIndex !== -1,
|
||||
if (initialRouteIndex === -1) {
|
||||
throw new Error(
|
||||
`Invalid initialRouteName '${initialRouteName}' for TabRouter. ` +
|
||||
`Should be one of ${order.map((n: *) => `"${n}"`).join(', ')}`
|
||||
);
|
||||
}
|
||||
return {
|
||||
getStateForAction(
|
||||
action: NavigationAction | { action: NavigationAction },
|
||||
|
@ -63,10 +63,11 @@ export default (
|
||||
let outputConfig = {};
|
||||
|
||||
if (Component.router) {
|
||||
invariant(
|
||||
route && routes && index != null,
|
||||
if (!route || !routes || index == null) {
|
||||
throw new Error(
|
||||
`Expect nav state to have routes and index, ${JSON.stringify(route)}`
|
||||
);
|
||||
}
|
||||
const childRoute = routes[index];
|
||||
const childNavigation = addNavigationHelpers({
|
||||
state: childRoute,
|
||||
|
@ -17,13 +17,14 @@ export default function getScreenForRouteName( // eslint-disable-line consistent
|
||||
): NavigationComponent {
|
||||
const routeConfig = routeConfigs[routeName];
|
||||
|
||||
invariant(
|
||||
routeConfig,
|
||||
if (!routeConfig) {
|
||||
throw new Error(
|
||||
`There is no route defined for key ${routeName}.\n` +
|
||||
`Must be one of: ${Object.keys(routeConfigs)
|
||||
.map((a: string) => `'${a}'`)
|
||||
.join(',')}`
|
||||
);
|
||||
}
|
||||
|
||||
if (routeConfig.screen) {
|
||||
return routeConfig.screen;
|
||||
@ -41,5 +42,5 @@ export default function getScreenForRouteName( // eslint-disable-line consistent
|
||||
return screen;
|
||||
}
|
||||
|
||||
invariant(false, `Route ${routeName} must define a screen or a getScreen.`);
|
||||
throw new Error(`Route ${routeName} must define a screen or a getScreen.`);
|
||||
}
|
||||
|
@ -18,8 +18,8 @@ function validateRouteConfigMap(routeConfigs: NavigationRouteConfigMap) {
|
||||
routeNames.forEach((routeName: string) => {
|
||||
const routeConfig = routeConfigs[routeName];
|
||||
|
||||
invariant(
|
||||
routeConfig.screen || routeConfig.getScreen,
|
||||
if (!routeConfig.screen && !routeConfig.getScreen) {
|
||||
throw new Error(
|
||||
`Route '${routeName}' should declare a screen. ` +
|
||||
'For example:\n\n' +
|
||||
"import MyScreen from './MyScreen';\n" +
|
||||
@ -28,18 +28,15 @@ function validateRouteConfigMap(routeConfigs: NavigationRouteConfigMap) {
|
||||
' screen: MyScreen,\n' +
|
||||
'}'
|
||||
);
|
||||
|
||||
if (routeConfig.screen && routeConfig.getScreen) {
|
||||
invariant(
|
||||
false,
|
||||
} else if (routeConfig.screen && routeConfig.getScreen) {
|
||||
throw new Error(
|
||||
`Route '${routeName}' should declare a screen or ` +
|
||||
'a getScreen, not both.'
|
||||
);
|
||||
}
|
||||
|
||||
if (routeConfig.screen) {
|
||||
invariant(
|
||||
typeof routeConfig.screen === 'function',
|
||||
if (routeConfig.screen && typeof routeConfig.screen !== 'function') {
|
||||
throw new Error(
|
||||
`The component for route '${routeName}' must be a ` +
|
||||
'React component. For example:\n\n' +
|
||||
"import MyScreen from './MyScreen';\n" +
|
||||
|
@ -1,5 +1,4 @@
|
||||
/* @flow */
|
||||
import invariant from '../utils/invariant';
|
||||
|
||||
import type { NavigationRoute } from '../TypeDefinition';
|
||||
|
||||
@ -15,8 +14,7 @@ export default (screenOptions: *, route: NavigationRoute) => {
|
||||
const deprecatedKey = keys.find((key: *) => deprecatedKeys.includes(key));
|
||||
|
||||
if (typeof screenOptions.title === 'function') {
|
||||
invariant(
|
||||
false,
|
||||
throw new Error(
|
||||
[
|
||||
`\`title\` cannot be defined as a function in navigation options for \`${route.routeName}\` screen. \n`,
|
||||
'Try replacing the following:',
|
||||
@ -33,8 +31,7 @@ export default (screenOptions: *, route: NavigationRoute) => {
|
||||
}
|
||||
|
||||
if (deprecatedKey && typeof screenOptions[deprecatedKey] === 'function') {
|
||||
invariant(
|
||||
false,
|
||||
throw new Error(
|
||||
[
|
||||
`\`${deprecatedKey}\` cannot be defined as a function in navigation options for \`${route.routeName}\` screen. \n`,
|
||||
'Try replacing the following:',
|
||||
@ -53,8 +50,7 @@ export default (screenOptions: *, route: NavigationRoute) => {
|
||||
}
|
||||
|
||||
if (deprecatedKey && typeof screenOptions[deprecatedKey] === 'object') {
|
||||
invariant(
|
||||
false,
|
||||
throw new Error(
|
||||
[
|
||||
`Invalid key \`${deprecatedKey}\` defined in navigation options for \`${route.routeName}\` screen.`,
|
||||
'\n',
|
||||
|
Loading…
x
Reference in New Issue
Block a user