close #161 support "addEvent" in any state

This commit is contained in:
Yanzhen Yu
2020-09-07 09:44:03 +08:00
parent 1bc5aaeb01
commit 9b8c7f755f
2 changed files with 17 additions and 1 deletions

View File

@@ -10,7 +10,7 @@ export class Timer {
public speed: number;
private actions: actionWithDelay[];
private raf: number;
private raf: number | null = null;
private liveMode: boolean;
constructor(actions: actionWithDelay[] = [], speed: number) {
@@ -61,6 +61,7 @@ export class Timer {
public clear() {
if (this.raf) {
cancelAnimationFrame(this.raf);
this.raf = null;
}
this.actions.length = 0;
}
@@ -73,6 +74,10 @@ export class Timer {
this.liveMode = mode;
}
public isActive() {
return this.raf !== null;
}
private findActionIndex(action: actionWithDelay): number {
let start = 0;
let end = this.actions.length - 1;