diff --git a/packages/core/src/getChildEventSubscriber.js b/packages/core/src/getChildEventSubscriber.js index 8839248a..99c232e0 100644 --- a/packages/core/src/getChildEventSubscriber.js +++ b/packages/core/src/getChildEventSubscriber.js @@ -69,8 +69,8 @@ export default function getChildEventSubscriber(addListener, key) { const lastRoutes = lastState && lastState.routes; const routes = state && state.routes; - const lastFocusKey = - lastState && lastState.routes && lastState.routes[lastState.index].key; + // const lastFocusKey = + // lastState && lastState.routes && lastState.routes[lastState.index].key; const focusKey = routes && routes[state.index].key; const isChildFocused = focusKey === key; diff --git a/packages/core/src/getChildNavigation.js b/packages/core/src/getChildNavigation.js index 441c05cb..ecc89723 100644 --- a/packages/core/src/getChildNavigation.js +++ b/packages/core/src/getChildNavigation.js @@ -1,7 +1,6 @@ import getChildEventSubscriber from './getChildEventSubscriber'; import getChildRouter from './getChildRouter'; import getNavigationActionCreators from './routers/getNavigationActionCreators'; -import invariant from './utils/invariant'; const createParamGetter = route => (paramName, defaultValue) => { const params = route.params; diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 365b66f3..653d802c 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -1,4 +1,4 @@ -/* eslint global-require: 0 */ +/* eslint-disable import/no-commonjs */ module.exports = { get StateUtils() { diff --git a/packages/core/src/routers/StackRouter.js b/packages/core/src/routers/StackRouter.js index beb8595c..ca782e71 100644 --- a/packages/core/src/routers/StackRouter.js +++ b/packages/core/src/routers/StackRouter.js @@ -15,7 +15,7 @@ function behavesLikePushAction(action) { ); } -const defaultActionCreators = (route, navStateKey) => ({}); +const defaultActionCreators = () => ({}); function isResetToRootStack(action) { return action.type === StackActions.RESET && action.key === null; diff --git a/packages/core/src/routers/SwitchRouter.js b/packages/core/src/routers/SwitchRouter.js index 1b028ebe..1753636d 100644 --- a/packages/core/src/routers/SwitchRouter.js +++ b/packages/core/src/routers/SwitchRouter.js @@ -7,7 +7,7 @@ import StackActions from './StackActions'; import validateRouteConfigMap from './validateRouteConfigMap'; import { createPathParser } from './pathUtils'; -const defaultActionCreators = (route, navStateKey) => ({}); +const defaultActionCreators = () => ({}); function childrenUpdateWithoutSwitchingIndex(actionType) { return [ @@ -36,7 +36,6 @@ export default (routeConfigs, config = {}) => { const initialRouteIndex = order.indexOf(initialRouteName); const childRouters = {}; order.forEach(routeName => { - const routeConfig = routeConfigs[routeName]; childRouters[routeName] = null; const screen = getScreenForRouteName(routeConfigs, routeName); if (screen.router) { diff --git a/packages/core/src/routers/__tests__/PathHandling-test.js b/packages/core/src/routers/__tests__/PathHandling-test.js index 0863565c..380fa76e 100644 --- a/packages/core/src/routers/__tests__/PathHandling-test.js +++ b/packages/core/src/routers/__tests__/PathHandling-test.js @@ -5,7 +5,6 @@ import React from 'react'; import SwitchRouter from '../SwitchRouter'; import StackRouter from '../StackRouter'; import TabRouter from '../TabRouter'; -import StackActions from '../StackActions'; import NavigationActions from '../../NavigationActions'; import { _TESTING_ONLY_normalize_keys } from '../KeyGenerator'; diff --git a/packages/core/src/routers/__tests__/Routers-test.js b/packages/core/src/routers/__tests__/Routers-test.js index a8e00e42..bbb1f643 100644 --- a/packages/core/src/routers/__tests__/Routers-test.js +++ b/packages/core/src/routers/__tests__/Routers-test.js @@ -19,7 +19,7 @@ const ROUTERS = { SwitchRouter, }; -const dummyEventSubscriber = (name, handler) => ({ +const dummyEventSubscriber = () => ({ remove: () => {}, }); diff --git a/packages/core/src/routers/__tests__/StackRouter-test.js b/packages/core/src/routers/__tests__/StackRouter-test.js index e86d6147..7a8dfd95 100644 --- a/packages/core/src/routers/__tests__/StackRouter-test.js +++ b/packages/core/src/routers/__tests__/StackRouter-test.js @@ -397,7 +397,6 @@ describe('StackRouter', () => { }, state ); - const barKey = state2.routes[1].routes[0].key; const state3 = router.getStateForAction( { type: StackActions.PUSH, @@ -429,7 +428,6 @@ describe('StackRouter', () => { }, state ); - const barKey = state2.routes[1].routes[0].key; const state3 = router.getStateForAction( { type: StackActions.POP, @@ -440,9 +438,6 @@ describe('StackRouter', () => { }); test('Handle navigation to nested navigator', () => { - const state = TestStackRouter.getStateForAction({ - type: NavigationActions.INIT, - }); const action = TestStackRouter.getActionForPathAndParams('fo/22/b/hello'); /* $FlowFixMe */ const state2 = TestStackRouter.getStateForAction(action); @@ -734,19 +729,17 @@ describe('StackRouter', () => { bar: { screen: () =>
}, }); const initState = TestRouter.getStateForAction(NavigationActions.init()); - for (key of ['a', null]) { - const pushedState = TestRouter.getStateForAction( - NavigationActions.navigate({ routeName: 'bar', key: 'a' }), - initState - ); - expect(pushedState.index).toEqual(1); - expect(pushedState.routes[1].routeName).toEqual('bar'); - const pushedTwiceState = TestRouter.getStateForAction( - NavigationActions.navigate({ routeName: 'bar', key: 'a' }), - pushedState - ); - expect(pushedTwiceState).toEqual(null); - } + const pushedState = TestRouter.getStateForAction( + NavigationActions.navigate({ routeName: 'bar', key: 'a' }), + initState + ); + expect(pushedState.index).toEqual(1); + expect(pushedState.routes[1].routeName).toEqual('bar'); + const pushedTwiceState = TestRouter.getStateForAction( + NavigationActions.navigate({ routeName: 'bar', key: 'a' }), + pushedState + ); + expect(pushedTwiceState).toEqual(null); }); // https://github.com/react-navigation/react-navigation/issues/4063 @@ -1905,7 +1898,7 @@ describe('StackRouter', () => { expect(activeState5.routes[activeState5.index].routeName).toEqual('Bar'); }); - test('order of handling navigate action is correct for nested stackrouters', () => { + test('order of handling navigate action is correct for nested stackrouters 2', () => { const Screen = () => ; const NestedStack = () => ; const OtherNestedStack = () => ; diff --git a/packages/core/src/routers/__tests__/TabRouter-test.js b/packages/core/src/routers/__tests__/TabRouter-test.js index e4a67cab..28438975 100644 --- a/packages/core/src/routers/__tests__/TabRouter-test.js +++ b/packages/core/src/routers/__tests__/TabRouter-test.js @@ -527,7 +527,7 @@ describe('TabRouter', () => { }); }); - test.only('Handles path configuration', () => { + test('Handles path configuration', () => { const ScreenA = () => ; const ScreenB = () => ; const router = TabRouter({ diff --git a/packages/core/src/routers/__tests__/createConfigGetter-test.js b/packages/core/src/routers/__tests__/createConfigGetter-test.js index 0a79d886..033d80b7 100644 --- a/packages/core/src/routers/__tests__/createConfigGetter-test.js +++ b/packages/core/src/routers/__tests__/createConfigGetter-test.js @@ -1,13 +1,11 @@ import { Component } from 'react'; import createConfigGetter from '../createConfigGetter'; -const dummyEventSubscriber = (name: string, handler: (*) => void) => ({ +const dummyEventSubscriber = () => ({ remove: () => {}, }); test('should get config for screen', () => { - /* eslint-disable react/no-multi-comp */ - class HomeScreen extends Component { static navigationOptions = ({ navigation }) => ({ title: `Welcome ${ @@ -147,8 +145,6 @@ test('should get config for screen', () => { }); test('should throw if the route does not exist', () => { - /* eslint-disable react/no-multi-comp */ - const HomeScreen = () => null; HomeScreen.navigationOptions = { title: 'Home screen', diff --git a/packages/core/src/routers/pathUtils.js b/packages/core/src/routers/pathUtils.js index be9eea1b..588209bd 100644 --- a/packages/core/src/routers/pathUtils.js +++ b/packages/core/src/routers/pathUtils.js @@ -1,17 +1,11 @@ +/* eslint-disable import/no-commonjs */ + import pathToRegexp, { compile } from 'path-to-regexp'; import NavigationActions from '../NavigationActions'; import invariant from '../utils/invariant'; const queryString = require('query-string'); -function isEmpty(obj) { - if (!obj) return true; - for (let key in obj) { - return false; - } - return true; -} - export const getParamsFromPath = (inputParams, pathMatch, pathMatchKeys) => { const params = pathMatch.slice(1).reduce( // iterate over matched path params @@ -123,9 +117,6 @@ export const createPathParser = ( const getActionForPathAndParams = (pathToResolve = '', inputParams = {}) => { // Attempt to match `pathToResolve` with a route in this router's routeConfigs, deferring to child routers - let matchedAction = null; - - // eslint-disable-next-line no-restricted-syntax for (const [routeName, path] of paths) { const { exactRe, exactReKeys, extendedPathRe, extendedPathReKeys } = path; const childRouter = childRouters[routeName]; @@ -152,7 +143,6 @@ export const createPathParser = ( } } - // eslint-disable-next-line no-restricted-syntax for (const [routeName, path] of paths) { const { extendedPathRe, extendedPathReKeys } = path; const childRouter = childRouters[routeName]; diff --git a/packages/core/src/utils/invariant.js b/packages/core/src/utils/invariant.js index ef63437c..99121cf0 100644 --- a/packages/core/src/utils/invariant.js +++ b/packages/core/src/utils/invariant.js @@ -1,3 +1,5 @@ +/* eslint-disable import/no-commonjs */ + /** * Use invariant() to assert state which your program assumes to be true. * @@ -9,7 +11,7 @@ * will remain to ensure logic does not differ in production. */ -var validateFormat = function(format) {}; +var validateFormat = function() {}; if (__DEV__) { validateFormat = function(format) { diff --git a/packages/core/src/views/__tests__/NavigationEvents-test.js b/packages/core/src/views/__tests__/NavigationEvents-test.js index ed29cef1..7b5bc0fb 100644 --- a/packages/core/src/views/__tests__/NavigationEvents-test.js +++ b/packages/core/src/views/__tests__/NavigationEvents-test.js @@ -3,7 +3,7 @@ import renderer from 'react-test-renderer'; import NavigationEvents from '../NavigationEvents'; import { NavigationProvider } from '../NavigationContext'; -const createListener = () => payload => {}; +const createListener = () => () => {}; // An easy way to create the 4 listeners prop const createEventListenersProp = () => ({ @@ -101,6 +101,7 @@ describe('NavigationEvents', () => { checkAddListenerCalledWith('willFocus', eventListenerProps.onWillFocus); checkAddListenerCalledWith('didBlur', eventListenerProps.onDidBlur); checkAddListenerCalledWith('didFocus', eventListenerProps.onDidFocus); + component.unmount(); }); it('add all listeners with navigation context', () => { @@ -122,6 +123,7 @@ describe('NavigationEvents', () => { checkAddListenerCalledWith('willFocus', eventListenerProps.onWillFocus); checkAddListenerCalledWith('didBlur', eventListenerProps.onDidBlur); checkAddListenerCalledWith('didFocus', eventListenerProps.onDidFocus); + component.unmount(); }); it('remove all listeners on unmount', () => { @@ -159,6 +161,7 @@ describe('NavigationEvents', () => { ); checkAddListenerCalled(1); checkAddListenerCalledWith('didFocus', listener); + component.unmount(); }); it('do not attempt to add/remove stable listeners on update', () => {