Browse Source

Pull request #1869: 无JIRA任务 生命周期严格按照beforemount render mounted的顺序执行

Merge in VISUAL/fineui from ~GUY/fineui:master to master

* commit '1835928fde2450d570aac587695b6255422ccddb':
  生命周期严格按照beforemount render mounted的顺序执行
es6
guy 4 years ago
parent
commit
06562750e0
  1. 140
      dist/fix/fix.compact.ie.js
  2. 140
      dist/fix/fix.compact.js
  3. 25
      src/core/4.widget.js

140
dist/fix/fix.compact.ie.js vendored

@ -163,76 +163,76 @@
needPop && popTarget();
};
BI.Widget.prototype._initElement = function () {
var self = this;
var render = BI.isFunction(this.options.render) ? this.options.render : this.render;
var els;
if (this.options.updateMode === "auto" && this._store) {
// 自动更新模式
var childComponents = {};
var rendered = false;
this._watchers.push(Fix.watch(this.model, function () {
if (rendered) {
var newEls = render && render.call(this);
BI.each(childComponents, function (i, childComponent) {
if (childComponent.component instanceof BI.Layout) {
return; // 布局的过滤掉
}
var nextProps = BI.get([newEls], childComponent.path);
if (nextProps) {
var shouldUpdate = childComponent.component.shouldUpdate && childComponent.component.shouldUpdate(nextProps);
childComponent.component._update(nextProps, shouldUpdate);
childComponent.props = BI.extend(childComponent.props, nextProps);
}
});
} else {
els = render && render.call(this);
function traverse (parent, path) {
BI.each(parent, function (i, child) {
var childPath = path.concat(i);
if (BI.isArray(child)) {
traverse(child, childPath);
} else if (BI.isPlainObject(child)) {
if (child.type) {
child.__ref = function (_ref) {
if (_ref) {
var comp = childComponents[this.getName()] = {};
comp.component = _ref;
comp.props = child;
comp.path = childPath;
} else {
delete childComponents[this.getName()];
}
};
}
traverse(child, childPath);
}
});
}
traverse([els], []);
rendered = true;
}
}));
} else {
els = render && render.call(this);
}
if (BI.isPlainObject(els)) {
els = [els];
}
if (BI.isArray(els)) {
BI.each(els, function (i, el) {
if (el) {
BI._lazyCreateWidget(el, {
element: self
});
}
});
}
// if (this._isRoot === true || !(this instanceof BI.Layout)) {
this._mount();
};
// BI.Widget.prototype._initElement = function () {
// var self = this;
// var render = BI.isFunction(this.options.render) ? this.options.render : this.render;
// var els;
// if (this.options.updateMode === "auto" && this._store) {
// // 自动更新模式
// var childComponents = {};
// var rendered = false;
// this._watchers.push(Fix.watch(this.model, function () {
// if (rendered) {
// var newEls = render && render.call(this);
// BI.each(childComponents, function (i, childComponent) {
// if (childComponent.component instanceof BI.Layout) {
// return; // 布局的过滤掉
// }
// var nextProps = BI.get([newEls], childComponent.path);
// if (nextProps) {
// var shouldUpdate = childComponent.component.shouldUpdate && childComponent.component.shouldUpdate(nextProps);
// childComponent.component._update(nextProps, shouldUpdate);
// childComponent.props = BI.extend(childComponent.props, nextProps);
// }
// });
// } else {
// els = render && render.call(this);
//
// function traverse (parent, path) {
// BI.each(parent, function (i, child) {
// var childPath = path.concat(i);
// if (BI.isArray(child)) {
// traverse(child, childPath);
// } else if (BI.isPlainObject(child)) {
// if (child.type) {
// child.__ref = function (_ref) {
// if (_ref) {
// var comp = childComponents[this.getName()] = {};
// comp.component = _ref;
// comp.props = child;
// comp.path = childPath;
// } else {
// delete childComponents[this.getName()];
// }
// };
// }
// traverse(child, childPath);
// }
// });
// }
//
// traverse([els], []);
// rendered = true;
// }
// }));
// } else {
// els = render && render.call(this);
// }
// if (BI.isPlainObject(els)) {
// els = [els];
// }
// if (BI.isArray(els)) {
// BI.each(els, function (i, el) {
// if (el) {
// BI._lazyCreateWidget(el, {
// element: self
// });
// }
// });
// }
// // if (this._isRoot === true || !(this instanceof BI.Layout)) {
// this._mount();
// };
var unMount = BI.Widget.prototype.__d;
BI.Widget.prototype.__d = function () {

140
dist/fix/fix.compact.js vendored

@ -163,76 +163,76 @@
needPop && popTarget();
};
BI.Widget.prototype._initElement = function () {
var self = this;
var render = BI.isFunction(this.options.render) ? this.options.render : this.render;
var els;
if (this.options.updateMode === "auto" && this._store) {
// 自动更新模式
var childComponents = {};
var rendered = false;
this._watchers.push(Fix.watch(this.model, function () {
if (rendered) {
var newEls = render && render.call(this);
BI.each(childComponents, function (i, childComponent) {
if (childComponent.component instanceof BI.Layout) {
return; // 布局的过滤掉
}
var nextProps = BI.get([newEls], childComponent.path);
if (nextProps) {
var shouldUpdate = childComponent.component.shouldUpdate && childComponent.component.shouldUpdate(nextProps);
childComponent.component._update(nextProps, shouldUpdate);
childComponent.props = BI.extend(childComponent.props, nextProps);
}
});
} else {
els = render && render.call(this);
function traverse (parent, path) {
BI.each(parent, function (i, child) {
var childPath = path.concat(i);
if (BI.isArray(child)) {
traverse(child, childPath);
} else if (BI.isPlainObject(child)) {
if (child.type) {
child.__ref = function (_ref) {
if (_ref) {
var comp = childComponents[this.getName()] = {};
comp.component = _ref;
comp.props = child;
comp.path = childPath;
} else {
delete childComponents[this.getName()];
}
};
}
traverse(child, childPath);
}
});
}
traverse([els], []);
rendered = true;
}
}));
} else {
els = render && render.call(this);
}
if (BI.isPlainObject(els)) {
els = [els];
}
if (BI.isArray(els)) {
BI.each(els, function (i, el) {
if (el) {
BI._lazyCreateWidget(el, {
element: self
});
}
});
}
// if (this._isRoot === true || !(this instanceof BI.Layout)) {
this._mount();
};
// BI.Widget.prototype._initElement = function () {
// var self = this;
// var render = BI.isFunction(this.options.render) ? this.options.render : this.render;
// var els;
// if (this.options.updateMode === "auto" && this._store) {
// // 自动更新模式
// var childComponents = {};
// var rendered = false;
// this._watchers.push(Fix.watch(this.model, function () {
// if (rendered) {
// var newEls = render && render.call(this);
// BI.each(childComponents, function (i, childComponent) {
// if (childComponent.component instanceof BI.Layout) {
// return; // 布局的过滤掉
// }
// var nextProps = BI.get([newEls], childComponent.path);
// if (nextProps) {
// var shouldUpdate = childComponent.component.shouldUpdate && childComponent.component.shouldUpdate(nextProps);
// childComponent.component._update(nextProps, shouldUpdate);
// childComponent.props = BI.extend(childComponent.props, nextProps);
// }
// });
// } else {
// els = render && render.call(this);
//
// function traverse (parent, path) {
// BI.each(parent, function (i, child) {
// var childPath = path.concat(i);
// if (BI.isArray(child)) {
// traverse(child, childPath);
// } else if (BI.isPlainObject(child)) {
// if (child.type) {
// child.__ref = function (_ref) {
// if (_ref) {
// var comp = childComponents[this.getName()] = {};
// comp.component = _ref;
// comp.props = child;
// comp.path = childPath;
// } else {
// delete childComponents[this.getName()];
// }
// };
// }
// traverse(child, childPath);
// }
// });
// }
//
// traverse([els], []);
// rendered = true;
// }
// }));
// } else {
// els = render && render.call(this);
// }
// if (BI.isPlainObject(els)) {
// els = [els];
// }
// if (BI.isArray(els)) {
// BI.each(els, function (i, el) {
// if (el) {
// BI._lazyCreateWidget(el, {
// element: self
// });
// }
// });
// }
// // if (this._isRoot === true || !(this instanceof BI.Layout)) {
// this._mount();
// };
var unMount = BI.Widget.prototype.__d;
BI.Widget.prototype.__d = function () {

25
src/core/4.widget.js

@ -7,7 +7,7 @@
*/
!(function () {
function callLifeHook(self, life) {
function callLifeHook (self, life) {
var hook = self.options[life] || self[life];
if (hook) {
var hooks = BI.isArray(hook) ? hook : [hook];
@ -98,8 +98,9 @@
_initRender: function () {
var self = this;
function render() {
function render () {
if (self.options.beforeRender || self.beforeRender) {
this.__async = true;
(self.options.beforeRender || self.beforeRender).call(self, BI.bind(self._render, self));
} else {
self._render();
@ -109,9 +110,6 @@
if (this.options.beforeInit || this.beforeInit) {
this.__asking = true;
(this.options.beforeInit || this.beforeInit).call(this, render);
if (this.__asking === true) {
this.__async = true;
}
} else {
render();
}
@ -123,6 +121,7 @@
this._initElement();
this._initEffects();
callLifeHook(this, "created");
this.__async = false;
},
_initCurrent: function () {
@ -204,6 +203,8 @@
_initElement: function () {
var self = this;
var isMounted = this._isMounted;
this.__async === true && isMounted && callLifeHook(this, "beforeMount");
var render = BI.isFunction(this.options.render) ? this.options.render : this.render;
var els = render && render.call(this);
if (BI.isPlainObject(els)) {
@ -218,9 +219,9 @@
}
});
}
// if (this._isRoot === true || !(this instanceof BI.Layout)) {
this._mount();
// }
this.__async === true && isMounted && callLifeHook(this, "mounted");
},
_setParent: function (parent) {
@ -242,7 +243,7 @@
return false;
}
layer = layer || 0;
lifeHook !== false && callLifeHook(this, "beforeMount");
lifeHook !== false && !this.__async && callLifeHook(this, "beforeMount");
this._isMounted = true;
for (var key in this._children) {
var child = this._children[key];
@ -266,8 +267,10 @@
var child = this._children[key];
child.__afterMount && child.__afterMount(lifeHook, predicate);
}
lifeHook !== false && callLifeHook(this, "mounted");
if (lifeHook !== false && !this.__async) {
callLifeHook(this, "mounted");
this.fireEvent(BI.Events.MOUNT);
}
predicate && predicate(this);
}
},
@ -593,12 +596,12 @@
BI.Widget.context = context = contextStack.pop();
};
function pushTarget(_current) {
function pushTarget (_current) {
if (current) currentStack.push(current);
BI.Widget.current = current = _current;
}
function popTarget() {
function popTarget () {
BI.Widget.current = current = currentStack.pop();
}

Loading…
Cancel
Save