import { SchedulerJob } from '../shared/svu' ; /**
 * 批量更新
 * life 标识为生命周期的控制
 */ const queue = [ ] ; const pendingPostFlushCbs = [ ] ; let resolvedPromise = Promise . resolve ( ) ; let currentFlushPromise = null ; let isFlushPending = false ; export function queueJob ( job ) { if ( ! queue . includes ( job ) ) { queue . push ( job ) ; queueFlush ( ) ; } } function queueFlush ( ) { if ( ! isFlushPending ) { isFlushPending = true ; currentFlushPromise = resolvedPromise . then ( flushJobs ) ; } } function flushJobs ( ) { isFlushPending = false ; for ( let i = 0 , len = queue . length ; i < len ; i ++ ) { queue [ i ] ( ) ; } queue . length = 0 ; flushPostFlushCbs ( ) ; } function flushPostFlushCbs ( ) { for ( let i = 0 , len = pendingPostFlushCbs . length ; i < len ; i ++ ) { pendingPostFlushCbs [ i ] ( ) ; } pendingPostFlushCbs . length = 0 ; } export function queuePostRenderEffect ( cb ) { pendingPostFlushCbs . push ( ... cb ) ; queueFlush ( ) ; } export function nextTick ( this , fn ? ) { const p = currentFlushPromise || resolvedPromise ; return fn ? p . then ( this ? fn . bind ( this ) : fn ) : p ; }