@@ -32,62 +32,59 @@ export default class ScrollTo extends React.Component {
3232
3333 componentDidMount ( ) {
3434 const { name, target } = this . props ;
35- const { current } = target || { } ;
3635
37- if ( current ) {
38- this . addEventListeners ( current ) ;
39- this . animate ( name , current [ name ] , this . props . value , 1 ) ;
36+ if ( target ) {
37+ this . addEventListeners ( target ) ;
38+ this . animate ( name , target [ name ] , this . props . value , 1 ) ;
4039 }
4140 }
4241
4342 componentDidUpdate ( prevProps ) {
4443 const { target : prevTarget } = prevProps ;
4544 const { target } = this . props ;
46- const { current : prevCurrent } = prevTarget || { } ;
47- const { current } = target || { } ;
4845 const scrollChanged = prevProps . value !== this . props . value ;
49- const targetChanged = prevCurrent !== current ;
46+ const targetChanged = prevTarget !== target ;
5047
5148 if ( targetChanged ) {
52- this . removeEventListeners ( prevCurrent ) ;
53- this . addEventListeners ( current ) ;
49+ this . removeEventListeners ( prevTarget ) ;
50+ this . addEventListeners ( target ) ;
5451 }
5552
56- if ( ( scrollChanged || targetChanged ) && current ) {
53+ if ( ( scrollChanged || targetChanged ) && target ) {
5754 const { name } = this . props ;
5855
59- this . animate ( name , current [ name ] , this . props . value , 1 ) ;
56+ this . animate ( name , target [ name ] , this . props . value , 1 ) ;
6057 }
6158 }
6259
6360 componentWillUnmount ( ) {
64- this . removeEventListeners ( this . props . target && this . props . target . current ) ;
61+ this . removeEventListeners ( this . props . target ) ;
6562 cancelAnimationFrame ( this . animator ) ;
6663 }
6764
68- addEventListeners ( current ) {
69- current && current . addEventListener ( 'pointerdown' , this . handleCancelAnimation , { passive : true } ) ;
65+ addEventListeners ( target ) {
66+ target && target . addEventListener ( 'pointerdown' , this . handleCancelAnimation , { passive : true } ) ;
7067 }
7168
72- removeEventListeners ( current ) {
73- current && current . removeEventListener ( 'pointerdown' , this . handleCancelAnimation ) ;
69+ removeEventListeners ( target ) {
70+ target && target . removeEventListener ( 'pointerdown' , this . handleCancelAnimation ) ;
7471 }
7572
7673 animate ( name , from , to , index , start = Date . now ( ) ) {
7774 if ( typeof to === 'number' ) {
7875 cancelAnimationFrame ( this . animator ) ;
7976
8077 this . animator = requestAnimationFrame ( ( ) => {
81- const { current } = this . props . target || { } ;
78+ const { target } = this . props ;
8279
83- if ( current ) {
80+ if ( target ) {
8481 let nextValue = step ( from , to , squareStepper , ( Date . now ( ) - start ) / 5 ) ;
8582
8683 if ( Math . abs ( to - nextValue ) < .5 ) {
8784 nextValue = to ;
8885 }
8986
90- current [ name ] = nextValue ;
87+ target [ name ] = nextValue ;
9188
9289 if ( to === nextValue ) {
9390 this . props . onEnd && this . props . onEnd ( true ) ;
0 commit comments