Skip to content

Commit

Permalink
Merge pull request #288 from connorsmallman/276
Browse files Browse the repository at this point in the history
fix #276
  • Loading branch information
ScriptedAlchemy authored Sep 17, 2018
2 parents 2f317d6 + e975180 commit 8911c8a
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 0 deletions.
41 changes: 41 additions & 0 deletions __tests__/__snapshots__/createLocationReducer.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,47 @@ Object {
}
`;

exports[`createLocationReducer() - reduces action.meta.location.kind being updated 1`] = `
Object {
"hasSSR": undefined,
"history": Object {
"entries": Array [
Object {
"hash": "",
"key": "345678",
"pathname": "/first",
"search": "",
"state": undefined,
},
Object {
"hash": "",
"key": "345678",
"pathname": "/first",
"search": "",
"state": undefined,
},
],
"index": 1,
"length": 2,
},
"kind": "load",
"pathname": "/first",
"payload": Object {
"param": "bar",
},
"prev": Object {
"pathname": "/first",
"payload": Object {},
"type": "FIRST",
},
"routesMap": Object {
"FIRST": "/first",
"SECOND": "/second/:param",
},
"type": "FIRST",
}
`;

exports[`getInitialState() returns state.history === undefined when using createBrowserHistory 1`] = `
Object {
"hasSSR": undefined,
Expand Down
24 changes: 24 additions & 0 deletions __tests__/createLocationReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,30 @@ it('createLocationReducer() - maintains address bar pathname state and current +
expectState(state)
})

it('createLocationReducer() - reduces action.meta.location.kind being updated', () => {
const { initialState, action, routesMap, expectState } = reducerParameters(
'FIRST',
'/first'
)

const reducer = createLocationReducer(initialState, routesMap)
const state = reducer(undefined, action) /*? */

const nextAction = {
...action,
meta: {
location: {
...action.meta.location,
kind: 'push'
}
}
}
const nextState = reducer(state, nextAction) /*? */

expectState(state)
expect(nextState.kind).toEqual('push')
})

it('locationReducer() reduces action.type === NOT_FOUND', () => {
const { initialState, routesMap, action } = reducerParameters(
NOT_FOUND,
Expand Down
14 changes: 14 additions & 0 deletions src/reducer/createLocationReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,20 @@ export default (initialState: LocationState, routesMap: RoutesMap) => (
routesMap
}
}
else if (
route &&
!action.error &&
(typeof route === 'string' || route.path) &&
(action.meta.location.current.pathname === state.pathname &&
action.meta.location.current.search === state.search &&
action.meta.location.kind !== state.kind
)
) {
return {
...state,
kind: action.meta.location.kind
}
}
else if (action.type === ADD_ROUTES) {
return {
...state,
Expand Down

0 comments on commit 8911c8a

Please sign in to comment.