From 142931ac44f82e0c1febffe37305565451b9b506 Mon Sep 17 00:00:00 2001 From: guy Date: Tue, 9 Mar 2021 19:47:49 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=B8=80=E4=B8=8Bcontext?= =?UTF-8?q?=E7=9A=84=E4=BC=A0=E9=80=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dist/fix/fix.compact.ie.js | 19 ++----------------- dist/fix/fix.compact.js | 24 ++---------------------- examples/dev.html | 2 +- src/core/base.js | 4 ++-- src/core/shortcut.js | 5 +++-- src/core/widget.js | 11 ++--------- 6 files changed, 12 insertions(+), 53 deletions(-) diff --git a/dist/fix/fix.compact.ie.js b/dist/fix/fix.compact.ie.js index 29450ec7a..5f1444316 100644 --- a/dist/fix/fix.compact.ie.js +++ b/dist/fix/fix.compact.ie.js @@ -82,7 +82,7 @@ if (p instanceof Fix.Model || p.store || p.__cacheStore) { break; } - p = p._parent || (p.options && p.options.element); + p = p._context || p._parent || (p.options && p.options.element); } if (p) { if (p instanceof Fix.Model) { @@ -93,21 +93,6 @@ } } - // var _create = BI.createWidget; - // BI.createWidget = function (item, options, context) { - // var pushed = false; - // if (BI.isWidget(options)) { - // pushContext(options); - // pushed = true; - // } else if (context != null) { - // pushContext(context); - // pushed = true; - // } - // var result = _create.apply(this, arguments); - // pushed && popContext(); - // return result; - // }; - _.each(["populate", "addItems", "prependItems"], function (name) { var old = BI.Loader.prototype[name]; BI.Loader.prototype[name] = function () { @@ -121,7 +106,7 @@ function createStore () { var needPop = false; if (_global.Fix && this._store) { - var store = findStore(this.options.context || this._parent || this.options.element); + var store = findStore(this.options.context || this._context || this._parent || this.options.element); if (store) { pushTarget(store); needPop = true; diff --git a/dist/fix/fix.compact.js b/dist/fix/fix.compact.js index 773ee7e47..44d4256b5 100644 --- a/dist/fix/fix.compact.js +++ b/dist/fix/fix.compact.js @@ -86,7 +86,7 @@ if (p instanceof Fix.Model || p.store || p.__cacheStore) { break; } - p = p._parent || (p.options && p.options.element); + p = p._context || p._parent || (p.options && p.options.element); } if (p) { if (p instanceof Fix.Model) { @@ -97,26 +97,6 @@ } } - // var _create = BI.createWidget; - // BI.createWidget = function (item, options, context) { - // var pushed = false; - // if (BI.isWidget(options)) { - // pushContext(options); - // pushed = true; - // } else if (context != null) { - // pushContext(context); - // pushed = true; - // } - // var result = _create.apply(this, arguments); - // // try { - // // var result = _create.apply(this, arguments); - // // } catch (e) { - // // console.error(e); - // // } - // pushed && popContext(); - // return result; - // }; - _.each(["populate", "addItems", "prependItems"], function (name) { var old = BI.Loader.prototype[name]; BI.Loader.prototype[name] = function () { @@ -134,7 +114,7 @@ function createStore () { var needPop = false; if (_global.Fix && this._store) { - var store = findStore(this.options.context || this._parent || this.options.element); + var store = findStore(this.options.context || this._context || this._parent || this.options.element); if (store) { pushTarget(store); needPop = true; diff --git a/examples/dev.html b/examples/dev.html index 6b6eb4f0c..03d77a1de 100644 --- a/examples/dev.html +++ b/examples/dev.html @@ -73,7 +73,7 @@ store.toggle(); }, 1000); BI.watch("text", function () { - child.populate(); + child.reset(); }); return function () { return { diff --git a/src/core/base.js b/src/core/base.js index b7948bf33..2bdc87d65 100644 --- a/src/core/base.js +++ b/src/core/base.js @@ -70,7 +70,7 @@ if (!_global.BI) { }, isWidget: function (widget) { - return widget instanceof BI.Widget || (BI.View && widget instanceof BI.View); + return widget instanceof BI.Widget; }, createWidgets: function (items, options, context) { @@ -107,7 +107,7 @@ if (!_global.BI) { el: innerAttr.shift() }); } - if (item.el instanceof BI.Widget || (BI.View && item.el instanceof BI.View)) { + if (item.el instanceof BI.Widget) { innerAttr.shift(); return BI.extend({}, outerAttr.shift(), { type: null }, item); } diff --git a/src/core/shortcut.js b/src/core/shortcut.js index 9f3b8492b..704d2a6b9 100644 --- a/src/core/shortcut.js +++ b/src/core/shortcut.js @@ -18,11 +18,12 @@ throw new Error("组件" + config.type + "未定义"); } var pushed = false; - if (context) { + var widget = new cls(); + widget._context = BI.Widget.context || context; + if (!BI.Widget.context && context) { pushed = true; BI.Widget.pushContext(context); } - var widget = new cls(); widget._initProps(config); widget._constructed(); widget._initRoot(); diff --git a/src/core/widget.js b/src/core/widget.js index 42628f1d4..f398de5d4 100644 --- a/src/core/widget.js +++ b/src/core/widget.js @@ -152,16 +152,9 @@ this._children = {}; if (BI.isWidget(o.element)) { this.element = this.options.element.element; - if (o.element instanceof BI.Widget) { - this._parent = o.element; - this._parent.addWidget(this.widgetName, this); - } else { - this._isRoot = true; - } + this._parent = o.element; + this._parent.addWidget(this.widgetName, this); } else if (o.element) { - // if (o.root !== true) { - // throw new Error("root is a required property"); - // } this.element = BI.Widget._renderEngine.createElement(this); this._isRoot = true; } else {