From ae6fcda4118f98bec9b2d7294d2dcab047180eda Mon Sep 17 00:00:00 2001 From: Michael Jackson Date: Fri, 13 Feb 2015 21:57:48 -0800 Subject: [PATCH] [changed] Rename Scrolling => ScrollHistory --- modules/{Scrolling.js => ScrollHistory.js} | 10 ++++++---- modules/createRouter.js | 12 ++++++------ 2 files changed, 12 insertions(+), 10 deletions(-) rename modules/{Scrolling.js => ScrollHistory.js} (91%) diff --git a/modules/Scrolling.js b/modules/ScrollHistory.js similarity index 91% rename from modules/Scrolling.js rename to modules/ScrollHistory.js index e5731a57da..d0abfef3af 100644 --- a/modules/Scrolling.js +++ b/modules/ScrollHistory.js @@ -26,9 +26,10 @@ function shouldUpdateScroll(state, prevState) { * Provides the router with the ability to manage window scroll position * according to its scroll behavior. */ -var Scrolling = { +var ScrollHistory = { statics: { + /** * Records curent scroll position as the last known position for the given URL path. */ @@ -48,11 +49,12 @@ var Scrolling = { return this.scrollHistory[path] || null; } + }, componentWillMount: function () { invariant( - this.getScrollBehavior() == null || canUseDOM, + this.constructor.getScrollBehavior() == null || canUseDOM, 'Cannot use scroll behavior without a DOM' ); }, @@ -69,7 +71,7 @@ var Scrolling = { if (!shouldUpdateScroll(this.state, prevState)) return; - var scrollBehavior = this.getScrollBehavior(); + var scrollBehavior = this.constructor.getScrollBehavior(); if (scrollBehavior) scrollBehavior.updateScrollPosition( @@ -80,4 +82,4 @@ var Scrolling = { }; -module.exports = Scrolling; +module.exports = ScrollHistory; diff --git a/modules/createRouter.js b/modules/createRouter.js index 2091631c15..122551785a 100644 --- a/modules/createRouter.js +++ b/modules/createRouter.js @@ -10,8 +10,8 @@ var HistoryLocation = require('./locations/HistoryLocation'); var RefreshLocation = require('./locations/RefreshLocation'); var StaticLocation = require('./locations/StaticLocation'); var NavigationContext = require('./NavigationContext'); +var ScrollHistory = require('./ScrollHistory'); var StateContext = require('./StateContext'); -var Scrolling = require('./Scrolling'); var createRoutesFromReactChildren = require('./Routing').createRoutesFromReactChildren; var isReactChildren = require('./isReactChildren'); var Transition = require('./Transition'); @@ -442,11 +442,15 @@ function createRouter(options) { location.removeChangeListener(Router.handleLocationChange); this.isRunning = false; + }, + + getScrollBehavior: function () { + return scrollBehavior; } }, - mixins: [ NavigationContext, StateContext, Scrolling ], + mixins: [ NavigationContext, StateContext, ScrollHistory ], propTypes: { children: PropTypes.falsy @@ -482,10 +486,6 @@ function createRouter(options) { return location; }, - getScrollBehavior: function () { - return scrollBehavior; - }, - getRouteAtDepth: function (depth) { var routes = this.state.routes; return routes && routes[depth];