Bladeren bron

refactor(scheduler): minor refactors (#240)

Dmitry Sharshakov 6 jaren geleden
bovenliggende
commit
7fd1fdde28
1 gewijzigde bestanden met toevoegingen van 7 en 5 verwijderingen
  1. 7 5
      packages/runtime-core/src/scheduler.ts

+ 7 - 5
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<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) {