From b41332458661c0f22acbc3d952021d548dae0f04 Mon Sep 17 00:00:00 2001 From: guy Date: Tue, 2 Mar 2021 20:03:33 +0800 Subject: [PATCH 1/3] update --- src/core/widget.js | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/src/core/widget.js b/src/core/widget.js index c9f6c03b0..3845fde79 100644 --- a/src/core/widget.js +++ b/src/core/widget.js @@ -226,31 +226,21 @@ * @returns {boolean} * @private */ - _mount: function (force, deep, lifeHook, predicate, layer, queue) { + _mount: function (force, deep, lifeHook, predicate) { var self = this; - if (!layer) { - layer = 0; - } - if (!queue) { - queue = []; - } if (!force && (this._isMounted || !this.isVisible() || this.__asking === true || !(this._isRoot === true || (this._parent && this._parent._isMounted === true)))) { return false; } lifeHook !== false && callLifeHook(this, "beforeMount"); this._isMounted = true; - queue.push(this); + // this._mountChildren && this._mountChildren(); 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, layer + 1, queue); + widget._mount && widget._mount(deep ? force : false, deep, lifeHook, predicate); }); this._mountChildren && this._mountChildren(); - if (layer === 0) { - BI.each(queue, function (i, w) { - w.__afterMount(lifeHook, predicate); - }); - } + this.__afterMount(lifeHook, predicate); return true; }, From 6b06a8e61561b5a8edf1c85de901eaeb6c2df85c Mon Sep 17 00:00:00 2001 From: guy Date: Tue, 2 Mar 2021 20:04:08 +0800 Subject: [PATCH 2/3] update --- src/core/widget.js | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/src/core/widget.js b/src/core/widget.js index 3845fde79..72c09f5bc 100644 --- a/src/core/widget.js +++ b/src/core/widget.js @@ -233,25 +233,18 @@ } lifeHook !== false && callLifeHook(this, "beforeMount"); this._isMounted = true; - // this._mountChildren && this._mountChildren(); 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); }); this._mountChildren && this._mountChildren(); - this.__afterMount(lifeHook, predicate); + lifeHook !== false && callLifeHook(this, "mounted"); + this.fireEvent(BI.Events.MOUNT); + predicate && predicate(this); return true; }, - __afterMount: function (lifeHook, predicate) { - if (this._isMounted) { - lifeHook !== false && callLifeHook(this, "mounted"); - this.fireEvent(BI.Events.MOUNT); - predicate && predicate(this); - } - }, - _mountChildren: null, _update: function (nextProps, shouldUpdate) { From 8641324dd307c2c2ac2b95a079f9faecfd053225 Mon Sep 17 00:00:00 2001 From: guy Date: Tue, 2 Mar 2021 21:10:21 +0800 Subject: [PATCH 3/3] update --- dist/fix/fix.compact.ie.js | 73 +++++++++++++++++++++++++++++++++++++- dist/fix/fix.compact.js | 2 +- src/core/widget.js | 23 +++++++++--- 3 files changed, 91 insertions(+), 7 deletions(-) diff --git a/dist/fix/fix.compact.ie.js b/dist/fix/fix.compact.ie.js index 38a51bf1d..29450ec7a 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 b523b5e6c..773ee7e47 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 72c09f5bc..f43bffce0 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) {