]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
refactor(scheduler): minor refactors (#240)
authorDmitry Sharshakov <d3dx12.xx@gmail.com>
Mon, 14 Oct 2019 02:41:23 +0000 (05:41 +0300)
committerEvan You <yyx990803@gmail.com>
Mon, 14 Oct 2019 02:41:23 +0000 (22:41 -0400)
packages/runtime-core/src/scheduler.ts

index 4c9f452a824690f3441eadb9bdb4124d53499c65..9af84cdbee0e7d2c84699ef75676956b6d1089bf 100644 (file)
@@ -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<void> {
 }
 
 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) {