From 6dc4355e1c2ab5d2c616fbc476a117c84a03f2fc Mon Sep 17 00:00:00 2001 From: guy Date: Sun, 28 Feb 2021 14:25:00 +0800 Subject: [PATCH] update --- dist/fix/fix.compact.js | 8 ++------ src/core/widget.js | 24 ++++++++++++++---------- src/core/wrapper/layout.js | 7 +++++-- 3 files changed, 21 insertions(+), 18 deletions(-) diff --git a/dist/fix/fix.compact.js b/dist/fix/fix.compact.js index 75eb3425b2..affb9a10b5 100644 --- a/dist/fix/fix.compact.js +++ b/dist/fix/fix.compact.js @@ -197,12 +197,8 @@ BI.each(childComponents, function (i, childComponent) { var nextProps = BI.get([newEls], childComponent.path); if (nextProps) { - var shouldUpdate; - if (shouldUpdate = (childComponent.component.shouldUpdate && childComponent.component.shouldUpdate(nextProps))) { - childComponent.component._update(shouldUpdate === true ? nextProps : shouldUpdate); - } else { - childComponent.component._update(nextProps); - } + var shouldUpdate = childComponent.component.shouldUpdate && childComponent.component.shouldUpdate(nextProps); + childComponent.component._update(nextProps, shouldUpdate); childComponent.props = BI.extend(childComponent.props, nextProps); } }); diff --git a/src/core/widget.js b/src/core/widget.js index 49d0d05a10..f8844ef282 100644 --- a/src/core/widget.js +++ b/src/core/widget.js @@ -74,8 +74,7 @@ shouldUpdate: null, - update: function () { - }, + update: null, beforeUpdate: null, @@ -248,16 +247,21 @@ _mountChildren: null, - _update: function (nextProps) { + _update: function (nextProps, shouldUpdate) { var o = this.options; callLifeHook(this, "beforeUpdate"); - var nextChange = {}; - BI.each(nextProps, function (key, value) { - if (o[key] !== value) { - nextChange[key] = value; - } - }); - var res = BI.isNotEmptyObject(nextChange) && this.update(nextChange); + if (shouldUpdate) { + var res = this.update && this.update(nextProps, shouldUpdate); + } else if (BI.isNull(shouldUpdate)) { + // 默认使用shallowCompare的方式进行更新 + var nextChange = {}; + BI.each(nextProps, function (key, value) { + if (o[key] !== value) { + nextChange[key] = value; + } + }); + var res = this.update && BI.isNotEmptyObject(nextChange) && this.update(nextChange); + } callLifeHook(this, "updated"); return res; }, diff --git a/src/core/wrapper/layout.js b/src/core/wrapper/layout.js index 8013ca0938..6b10e753d2 100644 --- a/src/core/wrapper/layout.js +++ b/src/core/wrapper/layout.js @@ -361,11 +361,14 @@ BI.Layout = BI.inherit(BI.Widget, { patchItem: function (oldVnode, vnode, index) { var shouldUpdate = this.shouldUpdateItem(index, vnode); + var child = this._children[this._getChildName(index)]; if (shouldUpdate) { - var child = this._children[this._getChildName(index)]; - return child._update(shouldUpdate === true ? this._getOptions(vnode) : shouldUpdate); + return child._update(this._getOptions(vnode), shouldUpdate); } if (shouldUpdate === null && !this._compare(oldVnode, vnode)) { + if (child.update) { + return child.update(this._getOptions(vnode)); + } return this.updateItemAt(index, vnode); } },