Browse Source

update

master
guy 4 years ago
parent
commit
6dc4355e1c
  1. 8
      dist/fix/fix.compact.js
  2. 12
      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) {
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);
}
});

12
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");
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 = BI.isNotEmptyObject(nextChange) && this.update(nextChange);
var res = this.update && BI.isNotEmptyObject(nextChange) && this.update(nextChange);
}
callLifeHook(this, "updated");
return res;
},

7
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);
if (shouldUpdate) {
var child = this._children[this._getChildName(index)];
return child._update(shouldUpdate === true ? this._getOptions(vnode) : shouldUpdate);
if (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);
}
},

Loading…
Cancel
Save