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

Commit 4afd74f

Browse files
committed
Confirm location change before listener invokation
1 parent c61c92c commit 4afd74f

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/sync.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,15 +99,22 @@ export default function syncHistoryWithStore(history, store, {
9999
...history,
100100
// The listeners are subscribed to the store instead of history
101101
listen(listener) {
102+
// Copy of last location.
103+
let lastPublishedLocation = getLocationInStore(true)
102104
// History listeners expect a synchronous call
103-
listener(getLocationInStore(true))
105+
listener(lastPublishedLocation)
104106

105107
// Keep track of whether we unsubscribed, as Redux store
106108
// only applies changes in subscriptions on next dispatch
107109
let unsubscribed = false
108110
const unsubscribeFromStore = store.subscribe(() => {
111+
const currentLocation = getLocationInStore(true)
112+
if (currentLocation === lastPublishedLocation) {
113+
return
114+
}
115+
lastPublishedLocation = currentLocation
109116
if (!unsubscribed) {
110-
listener(getLocationInStore(true))
117+
listener(lastPublishedLocation)
111118
}
112119
})
113120

0 commit comments

Comments
 (0)