Skip to content

Commit

Permalink
optimize scroll position saving (fix #1145)
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Feb 14, 2017
1 parent b769978 commit b6f96e9
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/util/push-state.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export function setStateKey (key: string) {
}

export function pushState (url?: string, replace?: boolean) {
saveScrollPosition()
// try...catch the pushState call to get around Safari
// DOM Exception 18 where it limits to 100 pushState calls
const history = window.history
Expand All @@ -48,7 +49,6 @@ export function pushState (url?: string, replace?: boolean) {
_key = genKey()
history.pushState({ key: _key }, '', url)
}
saveScrollPosition()
} catch (e) {
window.location[replace ? 'replace' : 'assign'](url)
}
Expand Down
3 changes: 1 addition & 2 deletions src/util/scroll.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@ const positionStore = Object.create(null)

export function setupScroll () {
window.addEventListener('popstate', e => {
saveScrollPosition()
if (e.state && e.state.key) {
setStateKey(e.state.key)
}
})

window.addEventListener('scroll', saveScrollPosition)
}

export function handleScroll (
Expand Down

0 comments on commit b6f96e9

Please sign in to comment.