Refactor scripts
This commit is contained in:
@ -9,15 +9,15 @@ const timeCapacity = 6.5
|
||||
// It checks the time used to process these mutations and if the time is over the
|
||||
// defined time capacity, it will pause and continue the mutations in the next frame.
|
||||
export default class MutationQueue {
|
||||
mutations: Array<() => void>
|
||||
onClearCallBacks: Array<() => void>
|
||||
private mutations: Array<() => void>
|
||||
private onClearCallBacks: Array<() => void>
|
||||
|
||||
constructor() {
|
||||
this.mutations = []
|
||||
this.onClearCallBacks = []
|
||||
}
|
||||
|
||||
queue(mutation: () => void) {
|
||||
public queue(mutation: () => void) {
|
||||
this.mutations.push(mutation)
|
||||
|
||||
if(this.mutations.length === 1) {
|
||||
@ -25,7 +25,20 @@ export default class MutationQueue {
|
||||
}
|
||||
}
|
||||
|
||||
mutateAll() {
|
||||
public wait(callBack: () => void) {
|
||||
if(this.mutations.length === 0) {
|
||||
callBack()
|
||||
return
|
||||
}
|
||||
|
||||
this.onClearCallBacks.push(callBack)
|
||||
}
|
||||
|
||||
public length() {
|
||||
return this.mutations.length
|
||||
}
|
||||
|
||||
private mutateAll() {
|
||||
const start = performance.now()
|
||||
|
||||
for(let i = 0; i < this.mutations.length; i++) {
|
||||
@ -45,7 +58,7 @@ export default class MutationQueue {
|
||||
this.clear()
|
||||
}
|
||||
|
||||
clear() {
|
||||
private clear() {
|
||||
this.mutations.length = 0
|
||||
|
||||
if(this.onClearCallBacks.length > 0) {
|
||||
@ -56,13 +69,4 @@ export default class MutationQueue {
|
||||
this.onClearCallBacks.length = 0
|
||||
}
|
||||
}
|
||||
|
||||
wait(callBack: () => void) {
|
||||
if(this.mutations.length === 0) {
|
||||
callBack()
|
||||
return
|
||||
}
|
||||
|
||||
this.onClearCallBacks.push(callBack)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user