Skip to content

Commit c9b5f51

Browse files
committed
navReducer: Use getCurrentRouteName selector, for simplicity.
1 parent d8836e6 commit c9b5f51

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/nav/__tests__/navReducer-test.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,17 @@ import deepFreeze from 'deep-freeze';
22

33
import { INITIAL_FETCH_COMPLETE } from '../../actionConstants';
44
import navReducer, { getStateForRoute } from '../navReducer';
5+
import NavigationService from '../NavigationService';
56

67
describe('navReducer', () => {
78
describe('INITIAL_FETCH_COMPLETE', () => {
89
test('do not mutate navigation state if already at the same route', () => {
10+
NavigationService.getState = jest.fn().mockReturnValue(
11+
deepFreeze({
12+
index: 0,
13+
routes: [{ routeName: 'main' }],
14+
}),
15+
);
916
const prevState = getStateForRoute('main');
1017

1118
const action = deepFreeze({

src/nav/navReducer.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import type { NavigationAction } from 'react-navigation';
33

44
import type { NavigationState, Action } from '../types';
5+
import { getCurrentRouteName } from './navSelectors';
56
import AppNavigator from './AppNavigator';
67
import { INITIAL_FETCH_COMPLETE } from '../actionConstants';
78

@@ -29,7 +30,7 @@ export const initialState = getStateForRoute('loading');
2930
export default (state: NavigationState = initialState, action: Action): NavigationState => {
3031
switch (action.type) {
3132
case INITIAL_FETCH_COMPLETE:
32-
return state.routes[0].routeName === 'main' ? state : getStateForRoute('main');
33+
return getCurrentRouteName() === 'main' ? state : getStateForRoute('main');
3334

3435
default: {
3536
// The `react-navigation` libdef says this only takes a NavigationAction,

0 commit comments

Comments
 (0)