Explorar o código

fix: fallback to Promise in non-DOM environments

Evan You %!s(int64=8) %!d(string=hai) anos
pai
achega
6d1f4cb89a
Modificáronse 1 ficheiros con 6 adicións e 0 borrados
  1. 6 0
      src/core/util/env.js

+ 6 - 0
src/core/util/env.js

@@ -103,6 +103,12 @@ export const nextTick = (function () {
     timerFunc = () => {
       port.postMessage(1)
     }
+  } else if (typeof Promise !== 'undefined' && isNative(Promise)) {
+    // use microtask in non-DOM environments, e.g. Weex
+    const p = Promise.resolve()
+    timerFunc = () => {
+      p.then(nextTickHandler)
+    }
   } else {
     // fallback to setTimeout
     /* istanbul ignore next */