diff --git a/dist/fix/fix.compact.ie.js b/dist/fix/fix.compact.ie.js index 38a51bf1d0..29450ec7a1 100644 --- a/dist/fix/fix.compact.ie.js +++ b/dist/fix/fix.compact.ie.js @@ -178,6 +178,77 @@ 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(); + }; + var unMount = BI.Widget.prototype.__d; BI.Widget.prototype.__d = function () { unMount.apply(this, arguments); @@ -197,7 +268,7 @@ delete this.__cacheStore; }; - _.each(["_mount"], function (name) { + _.each(["_mount", "__afterMount"], function (name) { var old = BI.Widget.prototype[name]; old && (BI.Widget.prototype[name] = function () { this.store && pushTarget(this.store); diff --git a/dist/fix/fix.compact.js b/dist/fix/fix.compact.js index b523b5e6cf..773ee7e47a 100644 --- a/dist/fix/fix.compact.js +++ b/dist/fix/fix.compact.js @@ -277,7 +277,7 @@ delete this.__cacheStore; }; - _.each(["_mount"], function (name) { + _.each(["_mount", "__afterMount"], function (name) { var old = BI.Widget.prototype[name]; old && (BI.Widget.prototype[name] = function () { this.store && pushTarget(this.store); diff --git a/src/core/widget.js b/src/core/widget.js index 72c09f5bcd..f43bffce0b 100644 --- a/src/core/widget.js +++ b/src/core/widget.js @@ -226,25 +226,38 @@ * @returns {boolean} * @private */ - _mount: function (force, deep, lifeHook, predicate) { + _mount: function (force, deep, lifeHook, predicate, layer) { var self = this; if (!force && (this._isMounted || !this.isVisible() || this.__asking === true || !(this._isRoot === true || (this._parent && this._parent._isMounted === true)))) { return false; } + layer = layer || 0; lifeHook !== false && callLifeHook(this, "beforeMount"); this._isMounted = true; BI.each(this._children, function (i, widget) { !self.isEnabled() && widget._setEnable(false); !self.isValid() && widget._setValid(false); - widget._mount && widget._mount(deep ? force : false, deep, lifeHook, predicate); + widget._mount && widget._mount(deep ? force : false, deep, lifeHook, predicate, layer + 1); }); this._mountChildren && this._mountChildren(); - lifeHook !== false && callLifeHook(this, "mounted"); - this.fireEvent(BI.Events.MOUNT); - predicate && predicate(this); + if (layer === 0) { + // 最后再统一执行生命周期 + this.__afterMount(lifeHook, predicate); + } return true; }, + __afterMount: function (lifeHook, predicate) { + if (this._isMounted) { + BI.each(this._children, function (i, widget) { + widget.__afterMount && widget.__afterMount(lifeHook, predicate); + }); + lifeHook !== false && callLifeHook(this, "mounted"); + this.fireEvent(BI.Events.MOUNT); + predicate && predicate(this); + } + }, + _mountChildren: null, _update: function (nextProps, shouldUpdate) {