| 57 | } |
| 58 | |
| 59 | export class AnimationFrameTicker implements ITicker { |
| 60 | private _rafid: number = 0 |
| 61 | private _cb: TickerCallback | null = null |
| 62 | |
| 63 | public get running(): boolean { return this._rafid != 0 } |
| 64 | |
| 65 | private _tick() { |
| 66 | if (this._cb) { this._cb() } |
| 67 | if (this._rafid) { |
| 68 | this._rafid = requestAnimationFrame(this._tick.bind(this)) |
| 69 | } |
| 70 | } |
| 71 | public start(cb: TickerCallback): void { |
| 72 | this.stop() |
| 73 | this._cb = cb |
| 74 | this._rafid = requestAnimationFrame(this._tick.bind(this)) |
| 75 | } |
| 76 | public stop(): void { |
| 77 | if (this._rafid) { |
| 78 | cancelAnimationFrame(this._rafid) |
| 79 | this._rafid = 0 |
| 80 | } |
| 81 | this._cb = null |
| 82 | } |
| 83 | public now(): number { return performance.now() } |
| 84 | } |
| 85 | |
| 86 | const TIMESCALE_MIN = 0, TIMESCALE_MAX = 5 |
| 87 |
nothing calls this directly
no outgoing calls
no test coverage detected