Added mutation queues

This commit is contained in:
2017-07-05 21:06:38 +02:00
parent 44803adc2d
commit 4a76c12803
3 changed files with 60 additions and 14 deletions

29
scripts/MutationQueue.ts Normal file
View File

@ -0,0 +1,29 @@
export class MutationQueue {
elements: Array<HTMLElement>
mutation: (elem: HTMLElement) => void
constructor(mutation: (elem: HTMLElement) => void) {
this.mutation = mutation
this.elements = []
}
queue(elem: HTMLElement) {
this.elements.push(elem)
if(this.elements.length === 1) {
window.requestAnimationFrame(() => this.mutateAll())
}
}
mutateAll() {
for(let i = 0; i < this.elements.length; i++) {
this.mutation(this.elements[i])
}
this.clear()
}
clear() {
this.elements.length = 0
}
}