From 54c204c74eb29f9f740815e4ab28701d1ee5e786 Mon Sep 17 00:00:00 2001 From: Kira Date: Mon, 11 Nov 2019 09:57:14 +0800 Subject: [PATCH] =?UTF-8?q?KERNEL-1646=20refactor:=20config=E5=8F=AF?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E5=8F=82=E6=95=B0=E5=B1=8F=E8=94=BD=E6=8E=89?= =?UTF-8?q?=E4=B9=8B=E5=89=8D=E6=B3=A8=E5=86=8C=E7=9A=84=E6=8F=92=E4=BB=B6?= =?UTF-8?q?=EF=BC=8Cinject=E6=94=BE=E5=88=B0=E7=AC=AC=E4=B8=80=E6=AC=A1cre?= =?UTF-8?q?ateWidget=E6=97=B6=E5=81=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core/inject.js | 59 +++++++++++++++++++++++++++++++++++--------- src/core/plugin.js | 11 ++++++--- src/core/shortcut.js | 1 + 3 files changed, 57 insertions(+), 14 deletions(-) diff --git a/src/core/inject.js b/src/core/inject.js index 3233b98ac..9236e2f75 100644 --- a/src/core/inject.js +++ b/src/core/inject.js @@ -47,17 +47,53 @@ providerInjection[xtype] = cls; }; - BI.config = function (type, configFn) { - if (constantInjection[type]) { - return constantInjection[type] = configFn(constantInjection[type]); - } - if (providerInjection[type]) { - if (!providers[type]) { - providers[type] = new providerInjection[type](); + var configFunctions = {}; + BI.config = function (type, configFn, options) { + if (BI.initialize) { + if (constantInjection[type]) { + return (constantInjection[type] = configFn(constantInjection[type])); } - return configFn(providers[type]); + if (providerInjection[type]) { + if (!providers[type]) { + providers[type] = new providerInjection[type](); + } + return configFn(providers[type]); + } + return BI.Plugin.configWidget(type, configFn); + } + if (!configFunctions[type]) { + configFunctions[type] = []; + BI.prepares.push(function () { + var stack = [], head; + for (var len = configFunctions[type].length, i = len - 1; i >= 0; i--) { + head = configFunctions[type][i]; + stack.push(i); + if (head.options && head.options.prevent) { + break; + } + } + for (var len = stack.length, i = len - 1; i >= 0; i--) { + head = configFunctions[type][stack[i]]; + if (constantInjection[type]) { + constantInjection[type] = head.fn(constantInjection[type]); + continue; + } + if (providerInjection[type]) { + if (!providers[type]) { + providers[type] = new providerInjection[type](); + } + head.fn(providers[type]); + continue; + } + BI.Plugin.configWidget(type, head.fn); + } + configFunctions[type] = null; + }); } - BI.Plugin.configWidget(type, configFn); + configFunctions[type].push({ + fn: configFn, + options: options + }) }; var actions = {}; @@ -189,7 +225,8 @@ } }; - var providers = {}, providerInstance = {}; + var providers = {}, + providerInstance = {}; BI.Providers = { getProvider: function (type, config) { @@ -242,4 +279,4 @@ return BI.Providers.getProvider(type, config); } }; -})(); +})(); \ No newline at end of file diff --git a/src/core/plugin.js b/src/core/plugin.js index 9d118cd57..323045a42 100644 --- a/src/core/plugin.js +++ b/src/core/plugin.js @@ -10,13 +10,16 @@ BI.Plugin = BI.Plugin || {}; if (_GlobalWidgetConfigFn) { _GlobalWidgetConfigFn(type, options); } + var res; if (_ConfigPlugin[type]) { for (var i = _ConfigPlugin[type].length - 1; i >= 0; i--) { - _ConfigPlugin[type][i](options); + if (res = _ConfigPlugin[type][i](options)) { + options = res; + } } } + // Deprecated if (_WidgetsPlugin[type]) { - var res; for (var i = _WidgetsPlugin[type].length - 1; i >= 0; i--) { if (res = _WidgetsPlugin[type][i](options)) { return res; @@ -59,7 +62,9 @@ BI.Plugin = BI.Plugin || {}; if (_ObjectPlugin[type]) { var res; for (var i = 0, len = _ObjectPlugin[type].length; i < len; i++) { - res = _ObjectPlugin[type][i](object); + if (res = _ObjectPlugin[type][i](object)) { + object = res; + }; } } return res || object; diff --git a/src/core/shortcut.js b/src/core/shortcut.js index 66e303216..0c98efc00 100644 --- a/src/core/shortcut.js +++ b/src/core/shortcut.js @@ -25,6 +25,7 @@ while (BI.prepares && BI.prepares.length > 0) { BI.prepares.shift()(); } + BI.initialize = true; var el, w; item || (item = {}); if (BI.isWidget(options)) {