From ec2477e5b351625137fcd7f3015bb3d6709e4131 Mon Sep 17 00:00:00 2001 From: Jimmy Jia Date: Thu, 5 May 2016 22:50:52 -0400 Subject: [PATCH] Switch ScrollBehavior to take getCurrentLocation --- src/ScrollBehavior.js | 8 ++++++-- src/index.js | 6 +++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/ScrollBehavior.js b/src/ScrollBehavior.js index fd2ff7c..66c1ed4 100644 --- a/src/ScrollBehavior.js +++ b/src/ScrollBehavior.js @@ -11,8 +11,8 @@ import { readState, saveState } from 'history/lib/DOMStateStorage'; const MAX_SCROLL_ATTEMPTS = 2; export default class ScrollBehavior { - constructor(history, getCurrentKey) { - this._getCurrentKey = getCurrentKey; + constructor(history, getCurrentLocation) { + this._getCurrentLocation = getCurrentLocation; // This helps avoid some jankiness in fighting against the browser's // default scroll behavior on `POP` transitions. @@ -109,6 +109,10 @@ export default class ScrollBehavior { saveState(currentKey, { ...state, scrollPosition }); }; + _getCurrentKey() { + return this._getCurrentLocation().key; + } + _cancelCheckScroll() { if (this._checkScrollHandle !== null) { requestAnimationFrame.cancel(this._checkScrollHandle); diff --git a/src/index.js b/src/index.js index 40e7eb1..31637c2 100644 --- a/src/index.js +++ b/src/index.js @@ -5,8 +5,8 @@ export default function withScroll(history, shouldUpdateScroll) { // currentLocation will always be defined when needed. let currentLocation = null; - function getCurrentKey() { - return currentLocation.key; + function getCurrentLocation() { + return currentLocation; } let listeners = []; @@ -32,7 +32,7 @@ export default function withScroll(history, shouldUpdateScroll) { function listen(listener) { if (listeners.length === 0) { - scrollBehavior = new ScrollBehavior(history, getCurrentKey); + scrollBehavior = new ScrollBehavior(history, getCurrentLocation); unlisten = history.listen(onChange); }