From b997da6fe5e58c353def5f82ea287209dd25b6f2 Mon Sep 17 00:00:00 2001 From: Fay Date: Tue, 13 Aug 2019 16:12:37 +0800 Subject: [PATCH 1/2] =?UTF-8?q?BI-47381=20deepEqual=20=E6=80=A7=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dist/fix/fix.ie.js | 114 ++++++++++++++++++++++----------------------- 1 file changed, 57 insertions(+), 57 deletions(-) diff --git a/dist/fix/fix.ie.js b/dist/fix/fix.ie.js index 7deee2e0c..5049fca0c 100644 --- a/dist/fix/fix.ie.js +++ b/dist/fix/fix.ie.js @@ -15,6 +15,8 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons $vm: falsy }; + var $$skips = ['$accessors', '$vbthis', '$vbsetter', '$vm']; + var originalMethods = []; _$1.each(['slice', 'splice'], function (method) { originalMethods[method] = Array.prototype[method]; @@ -128,7 +130,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons } else if (model && isPlainObject(model)) { result = {}; for (var key in model) { - if (!_$1.has($$skipArray, key)) { + if ($$skips.indexOf(key) === -1) { result[key] = toJSON(model[key]); } } @@ -148,15 +150,6 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons } return toJSON(obj); - - // const type = typeof obj; - // - // switch (type) { - // case 'object': - // return _.extend({}, obj); - // default: - // return obj; - // } } var nextTick = function () { @@ -263,8 +256,9 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons /* eslint no-use-before-define: ["off"] */ var deepEq = function deepEq(a, b, aStack, bStack) { // Unwrap any wrapped objects. - if (a instanceof _$1) a = a._wrapped; - if (b instanceof _$1) b = b._wrapped; + // 先注释,没走过 + // if (a instanceof _) a = a._wrapped; + // if (b instanceof _) b = b._wrapped; // Compare `[[Class]]` names. var className = toString.call(a); if (className !== toString.call(b)) return false; @@ -343,7 +337,11 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons while (length--) { // Deep compare each member key = keys[length]; - if (!(_$1.has(b, key) && eq(a[key], b[key], aStack, bStack))) return false; + if ($$skips.indexOf(key) !== -1) { + return true; + } + + if (!(Object.keys(b).indexOf(key) !== -1 && eq(a[key], b[key], aStack, bStack))) return false; } } // Remove the first object from the stack of traversed objects. @@ -371,37 +369,46 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons return deepEq(a, b, aStack, bStack); }; - var shadowEq = function shadowEq(a, b, aStack, bStack) { - // Identical objects are equal. `0 === -0`, but they aren't identical. - // See the [Harmony `egal` proposal](http://wiki.ecmascript.org/doku.php?id=harmony:egal). - if (a === b) return a !== 0 || 1 / a === 1 / b; - // `null` or `undefined` only equal to itself (strict comparison). - if (a == null || b == null) return false; - // `NaN`s are equivalent, but non-reflexive. - if (a !== a) return b !== b; - // Exhaust primitive checks - var type = typeof a; - if (type !== 'function' && type !== 'object' && typeof b != 'object') return false; + // export function isShadowEqual(a, b) { + // return shadowEq(a, b); + // } - // skip function - if (type === 'function') return true; + function isShadowEqual(a, b) { + if (a === b) return true; + + if (a && b && typeof a == 'object' && typeof b == 'object') { + if (a.constructor !== b.constructor) return false; + + var length, i, key, keys; + if (Array.isArray(a)) { + length = a.length; + if (length != b.length) return false; + for (i = length; i-- !== 0;) { + if (!isShadowEqual(a[i], b[i])) return false; + }return true; + } - if (Array.isArray(a) && Array.isArray(b) && (a.__ref__ || b.__ref__)) { - if (a.length !== b.length) return false; - // for (let i = 0; i < a.length; i++) { - // if (a[i] !== b[i]) { - // return false; - // } - // } + if (a.constructor === RegExp) return true; + if (a.valueOf !== Object.prototype.valueOf) return a.valueOf() === b.valueOf(); + if (a.toString !== Object.prototype.toString) return a.toString() === b.toString(); - return a.__ref__ === b.__ref__; - } + keys = Object.keys(a); + length = keys.length; + if (length !== Object.keys(b).length) return false; + + for (i = length; i-- !== 0;) { + if (!Object.prototype.hasOwnProperty.call(b, keys[i])) return false; + }for (i = length; i-- !== 0;) { + key = keys[i]; + if ($$skips.indexOf(key) !== -1) continue; + if (!isShadowEqual(a[key], b[key])) return false; + } - return deepEq(a, b, aStack, bStack); - }; + return true; + } - function isShadowEqual(a, b) { - return shadowEq(a, b); + // true if both NaN, false otherwise + return a !== a && b !== b; } var mixinInjection = {}; @@ -765,21 +772,13 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons }); } - function addToListenerQueue(vm, watcher, cur, last) { - var listener = { - id: watcher.id, - cb: _$1.bind(watcher.listener, vm, cur, last, vm) - }; - watcher.sync === true ? vm.syncListeners.push(listener) : vm.asyncListeners.push(listener); - } - function digestState(vm) { var dirty = false; _$1.each(vm._stateWatchers, function (watcher, key) { var cur = watcher.get(); var last = watcher.last; if (!isShadowEqual(cur, last)) { - addToListenerQueue(vm, watcher, cur, last); + // addToListenerQueue(vm, watcher, cur, last); vm.model[key] = cur; dirty = true; watcher.last = cloneShadow(cur); @@ -801,7 +800,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons var cur = watcher.get(); var last = watcher.last; if (!isShadowEqual(cur, last)) { - addToListenerQueue(vm, watcher, cur, last); + // addToListenerQueue(vm, watcher, cur, last); vm.model[key] = cur; dirty = true; dirtyQueue.push(key); @@ -902,15 +901,16 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons _$1.each(syncListeners, function (listener) { listener.cb(); }); - - nextTick(function () { - _$1.each(contextListeners, function (listener) { - listener.cb(); - }); - _$1.each(asyncListeners, function (listener) { - listener.cb(); + if (contextListeners.length !== 0 || asyncListeners.length !== 0) { + nextTick(function () { + _$1.each(contextListeners, function (listener) { + listener.cb(); + }); + _$1.each(asyncListeners, function (listener) { + listener.cb(); + }); }); - }); + } } function refreshAllDefineModel() { From fc8f9d7230d289139bb010f4e349b2fdecb95676 Mon Sep 17 00:00:00 2001 From: Fay Date: Tue, 13 Aug 2019 16:14:46 +0800 Subject: [PATCH 2/2] update --- dist/fix/fix.ie.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/dist/fix/fix.ie.js b/dist/fix/fix.ie.js index 5049fca0c..d99f860e2 100644 --- a/dist/fix/fix.ie.js +++ b/dist/fix/fix.ie.js @@ -256,9 +256,8 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons /* eslint no-use-before-define: ["off"] */ var deepEq = function deepEq(a, b, aStack, bStack) { // Unwrap any wrapped objects. - // 先注释,没走过 - // if (a instanceof _) a = a._wrapped; - // if (b instanceof _) b = b._wrapped; + if (a instanceof _) a = a._wrapped; + if (b instanceof _) b = b._wrapped; // Compare `[[Class]]` names. var className = toString.call(a); if (className !== toString.call(b)) return false;