Skip to content
This repository was archived by the owner on Oct 26, 2018. It is now read-only.

chore(history): update to history ^0.14.0 internally #131

Merged
merged 3 commits into from
Dec 23, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/basic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "rsr-basic-example",
"version": "0.0.0",
"dependencies": {
"history": "^1.13.1",
"history": "^1.14.0",
"react": "^0.14.2",
"react-dom": "^0.14.2",
"react-redux": "^4.0.0",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"eslint": "^1.10.3",
"eslint-config-rackt": "^1.1.1",
"expect": "^1.13.0",
"history": "^1.13.1",
"history": "^1.14.0",
"isparta": "^4.0.0",
"isparta-loader": "^2.0.0",
"karma": "^0.13.3",
Expand Down
7 changes: 5 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,11 @@ export function syncReduxAndRouter(history, store, selectRouterState = SELECT_ST
!locationsAreEqual(lastRoute, routing)) {

lastRoute = routing
const method = routing.replace ? 'replaceState' : 'pushState'
history[method](routing.state, routing.path)
const method = routing.replace ? 'replace' : 'push'
history[method]({
pathname: routing.path,
state: routing.state
})
}

})
Expand Down
56 changes: 36 additions & 20 deletions test/createTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ module.exports = function createTests(createHistory, name, reset = defaultReset)
devToolsStore = store.devToolsStore

// Set initial URL before syncing
history.pushState(null, '/foo')
history.push('/foo')

unsubscribe = syncReduxAndRouter(history, store)
})
Expand All @@ -185,7 +185,7 @@ module.exports = function createTests(createHistory, name, reset = defaultReset)
currentPath = location.pathname
})

history.pushState(null, '/bar')
history.push('/bar')
store.dispatch(pushPath('/baz'))

// By calling reset we expect DevTools to re-play the initial state
Expand All @@ -205,9 +205,9 @@ module.exports = function createTests(createHistory, name, reset = defaultReset)
})

// DevTools action #2
history.pushState(null, '/foo2')
history.push('/foo2')
// DevTools action #3
history.pushState(null, '/foo3')
history.push('/foo3')

// When we toggle an action, the devtools will revert the action
// and we therefore expect the history to update to the previous path
Expand Down Expand Up @@ -253,52 +253,66 @@ module.exports = function createTests(createHistory, name, reset = defaultReset)

it('syncs router -> redux', () => {
expect(store).toContainRoute({
path: '/'
path: '/',
state: null
})

history.pushState(null, '/foo')
history.push('/foo')
expect(store).toContainRoute({
path: '/foo',
replace: false,
state: null
})

history.pushState({ bar: 'baz' }, '/foo')
history.push({ state: { bar: 'baz' }, pathname: '/foo' })
expect(store).toContainRoute({
path: '/foo',
replace: true,
state: { bar: 'baz' }
})

history.replaceState(null, '/bar')
history.replace('/bar')
expect(store).toContainRoute({
path: '/bar',
replace: true,
state: null
})

history.pushState(null, '/bar')
history.push('/bar')
expect(store).toContainRoute({
path: '/bar',
replace: true,
state: null
})

history.pushState(null, '/bar?query=1')
history.push('/bar?query=1')
expect(store).toContainRoute({
path: '/bar?query=1',
replace: false,
state: null
})

history.replaceState({ bar: 'baz' }, '/bar?query=1')
history.push('/bar#baz')
expect(store).toContainRoute({
path: '/bar#baz',
replace: false,
state: null
})

history.replace({
state: { bar: 'baz' },
pathname: '/bar?query=1'
})
expect(store).toContainRoute({
path: '/bar?query=1',
replace: true,
state: { bar: 'baz' }
})

history.pushState({ bar: 'baz' }, '/bar?query=1#hash=2')
history.replace({
state: { bar: 'baz' },
pathname: '/bar?query=1#hash=2'
})
expect(store).toContainRoute({
path: '/bar?query=1#hash=2',
replace: true,
Expand All @@ -310,7 +324,7 @@ module.exports = function createTests(createHistory, name, reset = defaultReset)
expect(store).toContainRoute({
path: '/',
replace: false,
state: undefined
state: null
})

store.dispatch(pushPath('/foo'))
Expand Down Expand Up @@ -455,7 +469,7 @@ module.exports = function createTests(createHistory, name, reset = defaultReset)
}))
const history = createHistory()
syncReduxAndRouter(history, store, state => state.notRouting)
history.pushState(null, '/bar')
history.push('/bar')
expect(store.getState().notRouting.path).toEqual('/bar')
})

Expand All @@ -466,9 +480,10 @@ module.exports = function createTests(createHistory, name, reset = defaultReset)
const history = createHistory()
const unsubscribe = syncReduxAndRouter(history, store)

history.pushState(null, '/foo')
history.push('/foo')
expect(store).toContainRoute({
path: '/foo'
path: '/foo',
state: null
})

store.dispatch(pushPath('/bar'))
Expand All @@ -478,7 +493,7 @@ module.exports = function createTests(createHistory, name, reset = defaultReset)

unsubscribe()

history.pushState(null, '/foo')
history.push('/foo')
expect(store).toContainRoute({
path: '/bar'
})
Expand Down Expand Up @@ -523,17 +538,18 @@ module.exports = function createTests(createHistory, name, reset = defaultReset)
const store = createStore(combineReducers({
routing: routeReducer
}))
const history = useBasename(createHistory)({ basename:'/foobar' })
const history = useBasename(createHistory)({ basename: '/foobar' })
syncReduxAndRouter(history, store)

store.dispatch(pushPath('/bar'))
expect(store).toContainRoute({
path: '/bar'
})

history.pushState(undefined, '/baz')
history.push('/baz')
expect(store).toContainRoute({
path: '/baz'
path: '/baz',
state: null
})
})
})
Expand Down