Improved diffs
This commit is contained in:
@ -26,4 +26,53 @@ export class MutationQueue {
|
||||
clear() {
|
||||
this.elements.length = 0
|
||||
}
|
||||
}
|
||||
|
||||
export class CustomMutationQueue {
|
||||
mutations: Array<() => void>
|
||||
onClearCallBack: () => void
|
||||
timeCapacity = 6.5
|
||||
|
||||
constructor() {
|
||||
this.mutations = []
|
||||
}
|
||||
|
||||
queue(mutation: () => void) {
|
||||
this.mutations.push(mutation)
|
||||
|
||||
if(this.mutations.length === 1) {
|
||||
window.requestAnimationFrame(() => this.mutateAll())
|
||||
}
|
||||
}
|
||||
|
||||
mutateAll() {
|
||||
let start = performance.now()
|
||||
|
||||
for(let i = 0; i < this.mutations.length; i++) {
|
||||
if(performance.now() - start > this.timeCapacity) {
|
||||
let end = performance.now()
|
||||
// console.log(i, "mutations in", performance.now() - start, "ms")
|
||||
this.mutations = this.mutations.slice(i)
|
||||
window.requestAnimationFrame(() => this.mutateAll())
|
||||
return
|
||||
}
|
||||
|
||||
this.mutations[i]()
|
||||
}
|
||||
|
||||
this.clear()
|
||||
}
|
||||
|
||||
clear() {
|
||||
this.mutations.length = 0
|
||||
|
||||
if(this.onClearCallBack) {
|
||||
this.onClearCallBack()
|
||||
this.onClearCallBack = null
|
||||
}
|
||||
}
|
||||
|
||||
wait(callBack: () => void) {
|
||||
this.onClearCallBack = callBack
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user