From: Dmitry Sharshakov Date: Mon, 14 Oct 2019 02:41:23 +0000 (+0300) Subject: refactor(scheduler): minor refactors (#240) X-Git-Tag: v3.0.0-alpha.0~460 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=7fd1fdde2846c6c8d4c19f4a8779fe7ce7259cdb;p=thirdparty%2Fvuejs%2Fcore.git refactor(scheduler): minor refactors (#240) --- diff --git a/packages/runtime-core/src/scheduler.ts b/packages/runtime-core/src/scheduler.ts index 4c9f452a82..9af84cdbee 100644 --- a/packages/runtime-core/src/scheduler.ts +++ b/packages/runtime-core/src/scheduler.ts @@ -1,4 +1,5 @@ import { handleError, ErrorCodes } from './errorHandling' +import { isArray } from '@vue/shared' const queue: Function[] = [] const postFlushCbs: Function[] = [] @@ -11,7 +12,7 @@ export function nextTick(fn?: () => void): Promise { } export function queueJob(job: () => void) { - if (queue.indexOf(job) === -1) { + if (!queue.includes(job)) { queue.push(job) if (!isFlushing) { nextTick(flushJobs) @@ -20,17 +21,18 @@ export function queueJob(job: () => void) { } export function queuePostFlushCb(cb: Function | Function[]) { - if (Array.isArray(cb)) { - postFlushCbs.push.apply(postFlushCbs, cb) - } else { + if (!isArray(cb)) { postFlushCbs.push(cb) + } else { + postFlushCbs.push(...cb) } + if (!isFlushing) { nextTick(flushJobs) } } -const dedupe = (cbs: Function[]): Function[] => Array.from(new Set(cbs)) +const dedupe = (cbs: Function[]): Function[] => [...new Set(cbs)] export function flushPostFlushCbs() { if (postFlushCbs.length) {