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

Commit 4775cb1

Browse files
committed
Merge pull request #131 from justingreenberg/history-update
Update to use history ^0.14.0
2 parents a0bea5f + 203e773 commit 4775cb1

File tree

4 files changed

+43
-24
lines changed

4 files changed

+43
-24
lines changed

examples/basic/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "rsr-basic-example",
33
"version": "0.0.0",
44
"dependencies": {
5-
"history": "^1.13.1",
5+
"history": "^1.14.0",
66
"react": "^0.14.2",
77
"react-dom": "^0.14.2",
88
"react-redux": "^4.0.0",

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
"eslint": "^1.10.3",
4848
"eslint-config-rackt": "^1.1.1",
4949
"expect": "^1.13.0",
50-
"history": "^1.13.1",
50+
"history": "^1.14.0",
5151
"isparta": "^4.0.0",
5252
"isparta-loader": "^2.0.0",
5353
"karma": "^0.13.3",

src/index.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,11 @@ export function syncReduxAndRouter(history, store, selectRouterState = SELECT_ST
131131
!locationsAreEqual(lastRoute, routing)) {
132132

133133
lastRoute = routing
134-
const method = routing.replace ? 'replaceState' : 'pushState'
135-
history[method](routing.state, routing.path)
134+
const method = routing.replace ? 'replace' : 'push'
135+
history[method]({
136+
pathname: routing.path,
137+
state: routing.state
138+
})
136139
}
137140

138141
})

test/createTests.js

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ module.exports = function createTests(createHistory, name, reset = defaultReset)
170170
devToolsStore = store.devToolsStore
171171

172172
// Set initial URL before syncing
173-
history.pushState(null, '/foo')
173+
history.push('/foo')
174174

175175
unsubscribe = syncReduxAndRouter(history, store)
176176
})
@@ -185,7 +185,7 @@ module.exports = function createTests(createHistory, name, reset = defaultReset)
185185
currentPath = location.pathname
186186
})
187187

188-
history.pushState(null, '/bar')
188+
history.push('/bar')
189189
store.dispatch(pushPath('/baz'))
190190

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

207207
// DevTools action #2
208-
history.pushState(null, '/foo2')
208+
history.push('/foo2')
209209
// DevTools action #3
210-
history.pushState(null, '/foo3')
210+
history.push('/foo3')
211211

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

254254
it('syncs router -> redux', () => {
255255
expect(store).toContainRoute({
256-
path: '/'
256+
path: '/',
257+
state: null
257258
})
258259

259-
history.pushState(null, '/foo')
260+
history.push('/foo')
260261
expect(store).toContainRoute({
261262
path: '/foo',
262263
replace: false,
263264
state: null
264265
})
265266

266-
history.pushState({ bar: 'baz' }, '/foo')
267+
history.push({ state: { bar: 'baz' }, pathname: '/foo' })
267268
expect(store).toContainRoute({
268269
path: '/foo',
269270
replace: true,
270271
state: { bar: 'baz' }
271272
})
272273

273-
history.replaceState(null, '/bar')
274+
history.replace('/bar')
274275
expect(store).toContainRoute({
275276
path: '/bar',
276277
replace: true,
277278
state: null
278279
})
279280

280-
history.pushState(null, '/bar')
281+
history.push('/bar')
281282
expect(store).toContainRoute({
282283
path: '/bar',
283284
replace: true,
284285
state: null
285286
})
286287

287-
history.pushState(null, '/bar?query=1')
288+
history.push('/bar?query=1')
288289
expect(store).toContainRoute({
289290
path: '/bar?query=1',
290291
replace: false,
291292
state: null
292293
})
293294

294-
history.replaceState({ bar: 'baz' }, '/bar?query=1')
295+
history.push('/bar#baz')
296+
expect(store).toContainRoute({
297+
path: '/bar#baz',
298+
replace: false,
299+
state: null
300+
})
301+
302+
history.replace({
303+
state: { bar: 'baz' },
304+
pathname: '/bar?query=1'
305+
})
295306
expect(store).toContainRoute({
296307
path: '/bar?query=1',
297308
replace: true,
298309
state: { bar: 'baz' }
299310
})
300311

301-
history.pushState({ bar: 'baz' }, '/bar?query=1#hash=2')
312+
history.replace({
313+
state: { bar: 'baz' },
314+
pathname: '/bar?query=1#hash=2'
315+
})
302316
expect(store).toContainRoute({
303317
path: '/bar?query=1#hash=2',
304318
replace: true,
@@ -310,7 +324,7 @@ module.exports = function createTests(createHistory, name, reset = defaultReset)
310324
expect(store).toContainRoute({
311325
path: '/',
312326
replace: false,
313-
state: undefined
327+
state: null
314328
})
315329

316330
store.dispatch(pushPath('/foo'))
@@ -455,7 +469,7 @@ module.exports = function createTests(createHistory, name, reset = defaultReset)
455469
}))
456470
const history = createHistory()
457471
syncReduxAndRouter(history, store, state => state.notRouting)
458-
history.pushState(null, '/bar')
472+
history.push('/bar')
459473
expect(store.getState().notRouting.path).toEqual('/bar')
460474
})
461475

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

469-
history.pushState(null, '/foo')
483+
history.push('/foo')
470484
expect(store).toContainRoute({
471-
path: '/foo'
485+
path: '/foo',
486+
state: null
472487
})
473488

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

479494
unsubscribe()
480495

481-
history.pushState(null, '/foo')
496+
history.push('/foo')
482497
expect(store).toContainRoute({
483498
path: '/bar'
484499
})
@@ -523,17 +538,18 @@ module.exports = function createTests(createHistory, name, reset = defaultReset)
523538
const store = createStore(combineReducers({
524539
routing: routeReducer
525540
}))
526-
const history = useBasename(createHistory)({ basename:'/foobar' })
541+
const history = useBasename(createHistory)({ basename: '/foobar' })
527542
syncReduxAndRouter(history, store)
528543

529544
store.dispatch(pushPath('/bar'))
530545
expect(store).toContainRoute({
531546
path: '/bar'
532547
})
533548

534-
history.pushState(undefined, '/baz')
549+
history.push('/baz')
535550
expect(store).toContainRoute({
536-
path: '/baz'
551+
path: '/baz',
552+
state: null
537553
})
538554
})
539555
})

0 commit comments

Comments
 (0)