defer update if there's no component update

This commit is contained in:
MapleLeaf
2021-12-27 21:41:14 -06:00
parent 3d89b4fe6f
commit 9ab1f2b689
7 changed files with 61 additions and 8 deletions

View File

@@ -0,0 +1,20 @@
export class Timeout {
private timeoutId?: NodeJS.Timeout
constructor(
private readonly time: number,
private readonly callback: () => void,
) {}
run() {
this.cancel()
this.timeoutId = setTimeout(this.callback, this.time)
}
cancel() {
if (this.timeoutId) {
clearTimeout(this.timeoutId)
this.timeoutId = undefined
}
}
}