From 67d98c3b7c6a0e8f96ac125bf13ec33797d798d6 Mon Sep 17 00:00:00 2001 From: dailer Date: Mon, 7 Aug 2023 17:40:43 +0800 Subject: [PATCH] =?UTF-8?q?=E6=97=A0JIRA=20fix=E8=B0=83=E7=94=A8=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E7=9A=84=E5=85=88=E6=94=BE=E5=9C=A8compact=E9=87=8C?= =?UTF-8?q?=E9=9D=A2,=E4=B8=8D=E7=84=B6=E4=BC=9A=E5=BE=AA=E7=8E=AF?= =?UTF-8?q?=E5=BC=95=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/fineui/src/core/4.widget.js | 25 +---------- packages/fineui/src/fix/fix.compact.js | 59 +++++++++++++++++--------- 2 files changed, 40 insertions(+), 44 deletions(-) diff --git a/packages/fineui/src/core/4.widget.js b/packages/fineui/src/core/4.widget.js index 49dfef990..826cc5f84 100644 --- a/packages/fineui/src/core/4.widget.js +++ b/packages/fineui/src/core/4.widget.js @@ -25,7 +25,7 @@ import { import { OB } from "./3.ob"; import { Providers, _lazyCreateWidget } from "./5.inject"; import { DOM } from "./utils"; -import { Events, emptyFn, pixFormat } from "./constant"; +import { Events, pixFormat } from "./constant"; import { Plugin } from "./6.plugin"; import { _global } from "./0.foundation"; import { SystemProvider } from "./system"; @@ -336,29 +336,6 @@ export class Widget extends OB { } } - __watch(getter, handler, options) { - if (_global.Fix) { - this._watchers = this._watchers || []; - const watcher = new Fix.Watcher( - null, - () => getter.call(this, this), - (handler && - ((v) => { - handler.call(this, this, v); - })) || - emptyFn, - extend({ deep: true }, options) - ); - this._watchers.push(() => { - watcher.teardown(); - }); - - return watcher.value; - } else { - return getter(); - } - } - /** * 初始化根节点 * @private diff --git a/packages/fineui/src/fix/fix.compact.js b/packages/fineui/src/fix/fix.compact.js index 66aae8fc0..40b02fe8f 100644 --- a/packages/fineui/src/fix/fix.compact.js +++ b/packages/fineui/src/fix/fix.compact.js @@ -7,7 +7,7 @@ import { extend, isFunction, Widget, - Providers + Providers, emptyFn } from "@/core"; import { Fix } from "./fix"; @@ -76,7 +76,7 @@ function popTarget() { export const Model = Fix.Model; const oldWatch = Fix.watch; -Fix.watch = function (model, expOrFn, cb, options) { +Fix.watch = function(model, expOrFn, cb, options) { if (isPlainObject(cb)) { options = cb; cb = cb.handler; @@ -89,7 +89,7 @@ Fix.watch = function (model, expOrFn, cb, options) { this, model, expOrFn, - function () { + function() { options && options.store && pushTarget(options.store); let res; try { @@ -142,9 +142,9 @@ export function createStore() { if (this._store || this.options._store) { const store = Widget.findStore( this.options.context || - this._parent || - this.options.element || - this._context + this._parent || + this.options.element || + this._context ); if (store) { pushTarget(store); @@ -167,7 +167,7 @@ export function createStore() { } const _init = Widget.prototype._init; -Widget.prototype._init = function () { +Widget.prototype._init = function() { const needPop = createStore.call(this); try { _init.apply(this, arguments); @@ -178,7 +178,7 @@ Widget.prototype._init = function () { }; const __initWatch = Widget.prototype.__initWatch; -Widget.prototype.__initWatch = function () { +Widget.prototype.__initWatch = function() { __initWatch.apply(this, arguments); const workerMode = Providers.getProvider("bi.provider.system").getWorkerMode(); @@ -191,7 +191,7 @@ Widget.prototype.__initWatch = function () { }; const unMount = Widget.prototype.__destroy; -Widget.prototype.__destroy = function () { +Widget.prototype.__destroy = function() { try { unMount.apply(this, arguments); } catch (e) { @@ -213,19 +213,38 @@ Widget.prototype.__destroy = function () { delete this.__cacheStore; }; +Widget.prototype.__watch = function(getter, handler, options) { + this._watchers = this._watchers || []; + const watcher = new Fix.Watcher( + null, + () => getter.call(this, this), + (handler && + ((v) => { + handler.call(this, this, v); + })) || + emptyFn, + extend({ deep: true }, options) + ); + this._watchers.push(() => { + watcher.teardown(); + }); + + return watcher.value; +}; + _.each(["_render", "__afterRender", "_mount", "__afterMount"], (name) => { const old = Widget.prototype[name]; old && - (Widget.prototype[name] = function () { - this.store && pushTarget(this.store); - let res; - try { - res = old.apply(this, arguments); - } catch (e) { - console.error(e); - } - this.store && popTarget(); + (Widget.prototype[name] = function() { + this.store && pushTarget(this.store); + let res; + try { + res = old.apply(this, arguments); + } catch (e) { + console.error(e); + } + this.store && popTarget(); - return res; - }); + return res; + }); });