diff --git a/dist/fix/fix.compact.js b/dist/fix/fix.compact.js index 75eb3425b..affb9a10b 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 49d0d05a1..f8844ef28 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 8013ca093..6b10e753d 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); } },