Browse Source

update

master
guy 4 years ago
parent
commit
6dc4355e1c
  1. 8
      dist/fix/fix.compact.js
  2. 24
      src/core/widget.js
  3. 7
      src/core/wrapper/layout.js

8
dist/fix/fix.compact.js vendored

@ -197,12 +197,8 @@
BI.each(childComponents, function (i, childComponent) { BI.each(childComponents, function (i, childComponent) {
var nextProps = BI.get([newEls], childComponent.path); var nextProps = BI.get([newEls], childComponent.path);
if (nextProps) { if (nextProps) {
var shouldUpdate; var shouldUpdate = childComponent.component.shouldUpdate && childComponent.component.shouldUpdate(nextProps);
if (shouldUpdate = (childComponent.component.shouldUpdate && childComponent.component.shouldUpdate(nextProps))) { childComponent.component._update(nextProps, shouldUpdate);
childComponent.component._update(shouldUpdate === true ? nextProps : shouldUpdate);
} else {
childComponent.component._update(nextProps);
}
childComponent.props = BI.extend(childComponent.props, nextProps); childComponent.props = BI.extend(childComponent.props, nextProps);
} }
}); });

24
src/core/widget.js

@ -74,8 +74,7 @@
shouldUpdate: null, shouldUpdate: null,
update: function () { update: null,
},
beforeUpdate: null, beforeUpdate: null,
@ -248,16 +247,21 @@
_mountChildren: null, _mountChildren: null,
_update: function (nextProps) { _update: function (nextProps, shouldUpdate) {
var o = this.options; var o = this.options;
callLifeHook(this, "beforeUpdate"); callLifeHook(this, "beforeUpdate");
var nextChange = {}; if (shouldUpdate) {
BI.each(nextProps, function (key, value) { var res = this.update && this.update(nextProps, shouldUpdate);
if (o[key] !== value) { } else if (BI.isNull(shouldUpdate)) {
nextChange[key] = value; // 默认使用shallowCompare的方式进行更新
} var nextChange = {};
}); BI.each(nextProps, function (key, value) {
var res = BI.isNotEmptyObject(nextChange) && this.update(nextChange); if (o[key] !== value) {
nextChange[key] = value;
}
});
var res = this.update && BI.isNotEmptyObject(nextChange) && this.update(nextChange);
}
callLifeHook(this, "updated"); callLifeHook(this, "updated");
return res; return res;
}, },

7
src/core/wrapper/layout.js

@ -361,11 +361,14 @@ BI.Layout = BI.inherit(BI.Widget, {
patchItem: function (oldVnode, vnode, index) { patchItem: function (oldVnode, vnode, index) {
var shouldUpdate = this.shouldUpdateItem(index, vnode); var shouldUpdate = this.shouldUpdateItem(index, vnode);
var child = this._children[this._getChildName(index)];
if (shouldUpdate) { if (shouldUpdate) {
var child = this._children[this._getChildName(index)]; return child._update(this._getOptions(vnode), shouldUpdate);
return child._update(shouldUpdate === true ? this._getOptions(vnode) : shouldUpdate);
} }
if (shouldUpdate === null && !this._compare(oldVnode, vnode)) { if (shouldUpdate === null && !this._compare(oldVnode, vnode)) {
if (child.update) {
return child.update(this._getOptions(vnode));
}
return this.updateItemAt(index, vnode); return this.updateItemAt(index, vnode);
} }
}, },

Loading…
Cancel
Save