From fb32c9ef145f4b082e9ba2bf5b60cb1606ae0a24 Mon Sep 17 00:00:00 2001 From: guy Date: Sun, 28 Feb 2021 16:41:06 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=9F=E5=91=BD=E5=91=A8=E6=9C=9Fmount?= =?UTF-8?q?=EF=BC=8C=E5=85=88=E6=8A=8A=E5=AD=90dom=E8=8A=82=E7=82=B9?= =?UTF-8?q?=E5=88=9B=E5=BB=BA=E5=AE=8C=E5=86=8D=E6=95=B4=E4=B8=AA=E4=B8=80?= =?UTF-8?q?=E8=B5=B7append=E5=88=B0=E7=88=B6=E8=8A=82=E7=82=B9=E4=B8=8A?= =?UTF-8?q?=E5=8E=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dev.html | 23 ++++++++++++++--------- src/core/widget.js | 20 +++++++++++++++++--- 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/dev.html b/dev.html index 650cf45a6..9aa2fc79a 100644 --- a/dev.html +++ b/dev.html @@ -70,24 +70,26 @@ var store = BI.useStore(function () { return BI.Models.getModel("demo.model"); }); - setInterval(function () { - store.toggle(); - }, 1000); + // setInterval(function () { + // store.toggle(); + // }, 1000); return function () { return { type: "bi.vertical", vgap: 20, - items: [{ - type: "demo.child" - }, { - type: "demo.child" - }] + items: BI.makeArray(10000).map(function (i) { + return { + type: "bi.label", + text: i + }; + }) }; }; } }); BI.shortcut("demo.parent", Widget); - BI.createWidget({ + var time = performance.now(); + var widget = BI.createWidget({ type: "bi.absolute", items: [{ el: { @@ -97,7 +99,10 @@ left: 100 }], element: "#wrapper" + // root: true }); + // widget.element.appendTo("#wrapper"); + console.log(performance.now() - time); diff --git a/src/core/widget.js b/src/core/widget.js index f8844ef28..7b6b341f9 100644 --- a/src/core/widget.js +++ b/src/core/widget.js @@ -227,22 +227,36 @@ * @private */ _mount: function (force, deep, lifeHook, predicate) { + if (this.__beforeMount(force, deep, lifeHook, predicate)) { + this.__afterMount(lifeHook, predicate); + return true; + } + return false; + }, + + __beforeMount: function (force, deep, lifeHook, predicate) { var self = this; 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; - 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); + widget.__beforeMount && widget.__beforeMount(deep ? force : false, deep, lifeHook, predicate); + }); + this._mountChildren && this._mountChildren(); + return true; + }, + + __afterMount: function (lifeHook, predicate) { + 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); - return true; }, _mountChildren: null,