wip: adjust lifecycle
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
const queue: Function[] = []
|
||||
const postFlushCbs: Function[] = []
|
||||
const reversePostFlushCbs: Function[] = []
|
||||
const p = Promise.resolve()
|
||||
|
||||
let isFlushing = false
|
||||
@@ -20,32 +19,16 @@ export function queueJob(job: () => void, onError?: (err: Error) => void) {
|
||||
}
|
||||
|
||||
export function queuePostFlushCb(cb: Function | Function[]) {
|
||||
queuePostCb(cb, postFlushCbs)
|
||||
}
|
||||
|
||||
export function queueReversePostFlushCb(cb: Function | Function[]) {
|
||||
queuePostCb(cb, reversePostFlushCbs)
|
||||
}
|
||||
|
||||
function queuePostCb(cb: Function | Function[], queue: Function[]) {
|
||||
if (Array.isArray(cb)) {
|
||||
queue.push.apply(postFlushCbs, cb)
|
||||
postFlushCbs.push.apply(postFlushCbs, cb)
|
||||
} else {
|
||||
queue.push(cb)
|
||||
postFlushCbs.push(cb)
|
||||
}
|
||||
}
|
||||
|
||||
const dedupe = (cbs: Function[]): Function[] => Array.from(new Set(cbs))
|
||||
|
||||
export function flushPostFlushCbs() {
|
||||
if (reversePostFlushCbs.length) {
|
||||
const cbs = dedupe(reversePostFlushCbs)
|
||||
reversePostFlushCbs.length = 0
|
||||
let i = cbs.length
|
||||
while (i--) {
|
||||
cbs[i]()
|
||||
}
|
||||
}
|
||||
if (postFlushCbs.length) {
|
||||
const cbs = dedupe(postFlushCbs)
|
||||
postFlushCbs.length = 0
|
||||
|
||||
Reference in New Issue
Block a user