Skip to content

Commit d57d6f2

Browse files
committed
Use raf instead of a timeout to call flushClassNameQueue
1 parent fd437f7 commit d57d6f2

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

src/CSSTransitionGroupChild.js

+8-12
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,10 @@
1212

1313

1414
import { h, Component } from 'preact';
15-
import { getComponentBase, onlyChild } from './util';
15+
import { getComponentBase, onlyChild, requestAnimationFrame } from './util';
1616
import { addClass, removeClass } from './CSSCore';
1717
import { addEndEventListener, removeEndEventListener } from './TransitionEvents';
1818

19-
const TICK = 17;
20-
2119
export class CSSTransitionGroupChild extends Component {
2220
transition(animationType, finishCallback, timeout) {
2321
let node = getComponentBase(this);
@@ -62,16 +60,15 @@ export class CSSTransitionGroupChild extends Component {
6260
queueClass(className) {
6361
this.classNameQueue.push(className);
6462

65-
if (!this.timeout) {
66-
this.timeout = setTimeout(this.flushClassNameQueue, TICK);
63+
if (!this.rafHandle) {
64+
this.rafHandle = requestAnimationFrame(this.flushClassNameQueue);
6765
}
6866
}
6967

7068
stop() {
71-
if (this.timeout) {
72-
clearTimeout(this.timeout);
69+
if (this.rafHandle) {
7370
this.classNameQueue.length = 0;
74-
this.timeout = null;
71+
this.rafHandle = null;
7572
}
7673
if (this.endListener) {
7774
this.endListener();
@@ -83,7 +80,7 @@ export class CSSTransitionGroupChild extends Component {
8380
addClass(getComponentBase(this), this.classNameQueue.join(' '));
8481
}
8582
this.classNameQueue.length = 0;
86-
this.timeout = null;
83+
this.rafHandle = null;
8784
};
8885

8986
componentWillMount() {
@@ -92,9 +89,8 @@ export class CSSTransitionGroupChild extends Component {
9289
}
9390

9491
componentWillUnmount() {
95-
if (this.timeout) {
96-
clearTimeout(this.timeout);
97-
}
92+
this.classNameQueue.length = 0;
93+
this.rafHandle = null;
9894
this.transitionTimeouts.forEach((timeout) => {
9995
clearTimeout(timeout);
10096
});

0 commit comments

Comments
 (0)