12
12
13
13
14
14
import { h , Component } from 'preact' ;
15
- import { getComponentBase , onlyChild } from './util' ;
15
+ import { getComponentBase , onlyChild , requestAnimationFrame } from './util' ;
16
16
import { addClass , removeClass } from './CSSCore' ;
17
17
import { addEndEventListener , removeEndEventListener } from './TransitionEvents' ;
18
18
19
- const TICK = 17 ;
20
-
21
19
export class CSSTransitionGroupChild extends Component {
22
20
transition ( animationType , finishCallback , timeout ) {
23
21
let node = getComponentBase ( this ) ;
@@ -62,16 +60,15 @@ export class CSSTransitionGroupChild extends Component {
62
60
queueClass ( className ) {
63
61
this . classNameQueue . push ( className ) ;
64
62
65
- if ( ! this . timeout ) {
66
- this . timeout = setTimeout ( this . flushClassNameQueue , TICK ) ;
63
+ if ( ! this . rafHandle ) {
64
+ this . rafHandle = requestAnimationFrame ( this . flushClassNameQueue ) ;
67
65
}
68
66
}
69
67
70
68
stop ( ) {
71
- if ( this . timeout ) {
72
- clearTimeout ( this . timeout ) ;
69
+ if ( this . rafHandle ) {
73
70
this . classNameQueue . length = 0 ;
74
- this . timeout = null ;
71
+ this . rafHandle = null ;
75
72
}
76
73
if ( this . endListener ) {
77
74
this . endListener ( ) ;
@@ -83,7 +80,7 @@ export class CSSTransitionGroupChild extends Component {
83
80
addClass ( getComponentBase ( this ) , this . classNameQueue . join ( ' ' ) ) ;
84
81
}
85
82
this . classNameQueue . length = 0 ;
86
- this . timeout = null ;
83
+ this . rafHandle = null ;
87
84
} ;
88
85
89
86
componentWillMount ( ) {
@@ -92,9 +89,8 @@ export class CSSTransitionGroupChild extends Component {
92
89
}
93
90
94
91
componentWillUnmount ( ) {
95
- if ( this . timeout ) {
96
- clearTimeout ( this . timeout ) ;
97
- }
92
+ this . classNameQueue . length = 0 ;
93
+ this . rafHandle = null ;
98
94
this . transitionTimeouts . forEach ( ( timeout ) => {
99
95
clearTimeout ( timeout ) ;
100
96
} ) ;
0 commit comments