From 045a3ca58d40484a41049158f9a9b46a418a8720 Mon Sep 17 00:00:00 2001 From: windy <1374721899@qq.com> Date: Wed, 5 Feb 2020 14:47:54 +0800 Subject: [PATCH] =?UTF-8?q?BI-60021=20=E5=85=BC=E5=AE=B9=E6=80=A7-fix?= =?UTF-8?q?=E5=86=85=E9=83=A8nextTick=E5=9C=A8=E7=81=AB=E7=8B=90=E4=B8=8B?= =?UTF-8?q?=E6=9C=89=E5=85=BC=E5=AE=B9=E9=97=AE=E9=A2=98=EF=BC=88=E5=85=88?= =?UTF-8?q?=E8=BF=98=E5=8E=9F=EF=BC=8C=E5=B7=B2=E5=BB=BA=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?=E7=A0=94=E7=A9=B6=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dist/fix/fix.js | 81 +++++++++++++++++++------------------------------ 1 file changed, 32 insertions(+), 49 deletions(-) diff --git a/dist/fix/fix.js b/dist/fix/fix.js index 1a468c9ea..f8461340a 100644 --- a/dist/fix/fix.js +++ b/dist/fix/fix.js @@ -120,59 +120,42 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons } } - // Here we have async deferring wrappers using microtasks. - // In 2.5 we used (macro) tasks (in combination with microtasks). - // However, it has subtle problems when state is changed right before repaint - // (e.g. #6813, out-in transitions). - // Also, using (macro) tasks in event handler would cause some weird behaviors - // that cannot be circumvented (e.g. #7109, #7153, #7546, #7834, #8109). - // So we now use microtasks everywhere, again. - // A major drawback of this tradeoff is that there are some scenarios - // where microtasks have too high a priority and fire in between supposedly - // sequential events (e.g. #4521, #6690, which have workarounds) - // or even between bubbling of the same event (#6566). - - // The nextTick behavior leverages the microtask queue, which can be accessed - // via either native Promise.then or MutationObserver. - // MutationObserver has wider support, however it is seriously bugged in - // UIWebView in iOS >= 9.3.3 when triggered in touch event handlers. It - // completely stops working after triggering a few times... so, if native - // Promise is available, we will use it: - /* istanbul ignore next, $flow-disable-line */ - if (typeof Promise !== 'undefined' && isNative(Promise)) { - var p = Promise.resolve(); - timerFunc = function timerFunc() { - p.then(nextTickHandler); - }; - } else if (!isIE && typeof MutationObserver !== 'undefined' && (isNative(MutationObserver) || - // PhantomJS and iOS 7.x - MutationObserver.toString() === '[object MutationObserverConstructor]')) { - // Use MutationObserver where native Promise is not available, - // e.g. PhantomJS, iOS7, Android 4.4 - // (#6466 MutationObserver is unreliable in IE11) - var counter = 1; - var observer = new MutationObserver(nextTickHandler); - var textNode = document.createTextNode(String(counter)); - observer.observe(textNode, { - characterData: true - }); - timerFunc = function timerFunc() { - counter = (counter + 1) % 2; - textNode.data = String(counter); - }; - } else if (typeof setImmediate !== 'undefined' && isNative(setImmediate)) { - // Fallback to setImmediate. - // Technically it leverages the (macro) task queue, - // but it is still a better choice than setTimeout. + // An asynchronous deferring mechanism. + // In pre 2.4, we used to use microtasks (Promise/MutationObserver) + // but microtasks actually has too high a priority and fires in between + // supposedly sequential events (e.g. #4521, #6690) or even between + // bubbling of the same event (#6566). Technically setImmediate should be + // the ideal choice, but it's not available everywhere; and the only polyfill + // that consistently queues the callback after all DOM events triggered in the + // same loop is by using MessageChannel. + /* istanbul ignore if */ + if (typeof setImmediate !== 'undefined' && isNative(setImmediate)) { timerFunc = function timerFunc() { setImmediate(nextTickHandler); }; - } else { - // Fallback to setTimeout. + } else if (typeof MessageChannel !== 'undefined' && (isNative(MessageChannel) || + // PhantomJS + MessageChannel.toString() === '[object MessageChannelConstructor]')) { + var channel = new MessageChannel(); + var port = channel.port2; + channel.port1.onmessage = nextTickHandler; timerFunc = function timerFunc() { - setTimeout(nextTickHandler, 0); + port.postMessage(1); }; - } + } else + /* istanbul ignore next */ + if (typeof Promise !== 'undefined' && isNative(Promise)) { + // use microtask in non-DOM environments, e.g. Weex + var p = Promise.resolve(); + timerFunc = function timerFunc() { + p.then(nextTickHandler); + }; + } else { + // fallback to setTimeout + timerFunc = function timerFunc() { + setTimeout(nextTickHandler, 0); + }; + } return function queueNextTick(cb, ctx) { var _resolve = void 0; @@ -376,7 +359,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons uniq[name] = true; } } - //添加访问器属性 + //添加访问器属性 for (name in accessors) { if (uniq[name]) { continue;