From 7fd1fdde2846c6c8d4c19f4a8779fe7ce7259cdb Mon Sep 17 00:00:00 2001 From: Dmitry Sharshakov Date: Mon, 14 Oct 2019 05:41:23 +0300 Subject: [PATCH] refactor(scheduler): minor refactors (#240) --- packages/runtime-core/src/scheduler.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/packages/runtime-core/src/scheduler.ts b/packages/runtime-core/src/scheduler.ts index 4c9f452a..9af84cdb 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) {