@@ -32,38 +32,43 @@ function shouldUpdateScroll(state, prevState) {
32
32
*/
33
33
var Scrolling = {
34
34
35
+ statics : {
36
+ /**
37
+ * Records curent scroll position as the last known position for the given URL path.
38
+ */
39
+ recordScrollPosition : function ( path ) {
40
+ if ( ! this . scrollHistory )
41
+ this . scrollHistory = { } ;
42
+
43
+ this . scrollHistory [ path ] = getWindowScrollPosition ( ) ;
44
+ } ,
45
+
46
+ /**
47
+ * Returns the last known scroll position for the given URL path.
48
+ */
49
+ getScrollPosition : function ( path ) {
50
+ if ( ! this . scrollHistory )
51
+ this . scrollHistory = { } ;
52
+
53
+ return this . scrollHistory [ path ] || null ;
54
+ }
55
+ } ,
56
+
35
57
componentWillMount : function ( ) {
36
58
invariant (
37
59
this . getScrollBehavior ( ) == null || canUseDOM ,
38
60
'Cannot use scroll behavior without a DOM'
39
61
) ;
40
-
41
- this . _scrollHistory = { } ;
42
62
} ,
43
63
44
64
componentDidMount : function ( ) {
45
65
this . _updateScroll ( ) ;
46
66
} ,
47
67
48
- componentWillUpdate : function ( ) {
49
- this . _scrollHistory [ this . state . path ] = getWindowScrollPosition ( ) ;
50
- } ,
51
-
52
68
componentDidUpdate : function ( prevProps , prevState ) {
53
69
this . _updateScroll ( prevState ) ;
54
70
} ,
55
71
56
- componentWillUnmount : function ( ) {
57
- delete this . _scrollHistory ;
58
- } ,
59
-
60
- /**
61
- * Returns the last known scroll position for the given URL path.
62
- */
63
- getScrollPosition : function ( path ) {
64
- return this . _scrollHistory [ path ] || null ;
65
- } ,
66
-
67
72
_updateScroll : function ( prevState ) {
68
73
if ( ! shouldUpdateScroll ( this . state , prevState ) ) {
69
74
return ;
@@ -73,7 +78,7 @@ var Scrolling = {
73
78
74
79
if ( scrollBehavior )
75
80
scrollBehavior . updateScrollPosition (
76
- this . getScrollPosition ( this . state . path ) ,
81
+ this . constructor . getScrollPosition ( this . state . path ) ,
77
82
this . state . action
78
83
) ;
79
84
}
0 commit comments