From 54c204c74eb29f9f740815e4ab28701d1ee5e786 Mon Sep 17 00:00:00 2001 From: Kira Date: Mon, 11 Nov 2019 09:57:14 +0800 Subject: [PATCH 1/3] =?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)) { From 49b8c4ccd5e7618ae35541969b1da8a26438a30e Mon Sep 17 00:00:00 2001 From: Kira Date: Mon, 11 Nov 2019 10:36:02 +0800 Subject: [PATCH 2/3] =?UTF-8?q?KERNEL-1646=20refactor:=20=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E5=91=BD=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core/inject.js | 14 +++++++------- src/core/shortcut.js | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/core/inject.js b/src/core/inject.js index 9236e2f75..afd03e3e7 100644 --- a/src/core/inject.js +++ b/src/core/inject.js @@ -49,7 +49,7 @@ var configFunctions = {}; BI.config = function (type, configFn, options) { - if (BI.initialize) { + if (BI.initialized) { if (constantInjection[type]) { return (constantInjection[type] = configFn(constantInjection[type])); } @@ -64,16 +64,16 @@ 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); + var stack = [], head, count, index; + for (count = configFunctions[type].length, index = count - 1; index >= 0; index--) { + head = configFunctions[type][index]; + stack.push(index); if (head.options && head.options.prevent) { break; } } - for (var len = stack.length, i = len - 1; i >= 0; i--) { - head = configFunctions[type][stack[i]]; + for (count = stack.length, index = count - 1; index >= 0; index--) { + head = configFunctions[type][stack[index]]; if (constantInjection[type]) { constantInjection[type] = head.fn(constantInjection[type]); continue; diff --git a/src/core/shortcut.js b/src/core/shortcut.js index 0c98efc00..449b4cdff 100644 --- a/src/core/shortcut.js +++ b/src/core/shortcut.js @@ -25,7 +25,7 @@ while (BI.prepares && BI.prepares.length > 0) { BI.prepares.shift()(); } - BI.initialize = true; + BI.initialized = true; var el, w; item || (item = {}); if (BI.isWidget(options)) { From eaaca33db2647474bcd93cbd1a4fdab7fc8e25bb Mon Sep 17 00:00:00 2001 From: Kira Date: Tue, 12 Nov 2019 00:11:37 +0800 Subject: [PATCH 3/3] =?UTF-8?q?KERNEL-1646=20refactor:=20=E5=8E=BB?= =?UTF-8?q?=E6=8E=89config=E4=B8=AD=E4=BC=A0=E7=9A=84options?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core/base.js | 1 + src/core/inject.js | 25 +++++++------------------ src/core/shortcut.js | 5 +---- 3 files changed, 9 insertions(+), 22 deletions(-) diff --git a/src/core/base.js b/src/core/base.js index a79b4eca4..2dc4b7052 100644 --- a/src/core/base.js +++ b/src/core/base.js @@ -456,6 +456,7 @@ if (!_global.BI) { while (BI.prepares && BI.prepares.length > 0) { BI.prepares.shift()(); } + BI.initialized = true; }, has: function (obj, keys) { diff --git a/src/core/inject.js b/src/core/inject.js index afd03e3e7..30a15a2f8 100644 --- a/src/core/inject.js +++ b/src/core/inject.js @@ -48,7 +48,7 @@ }; var configFunctions = {}; - BI.config = function (type, configFn, options) { + BI.config = function (type, configFn) { if (BI.initialized) { if (constantInjection[type]) { return (constantInjection[type] = configFn(constantInjection[type])); @@ -64,36 +64,25 @@ if (!configFunctions[type]) { configFunctions[type] = []; BI.prepares.push(function () { - var stack = [], head, count, index; - for (count = configFunctions[type].length, index = count - 1; index >= 0; index--) { - head = configFunctions[type][index]; - stack.push(index); - if (head.options && head.options.prevent) { - break; - } - } - for (count = stack.length, index = count - 1; index >= 0; index--) { - head = configFunctions[type][stack[index]]; + var queue = configFunctions[type]; + for (var i = 0; i < queue.length; i++) { if (constantInjection[type]) { - constantInjection[type] = head.fn(constantInjection[type]); + constantInjection[type] = queue[i](constantInjection[type]); continue; } if (providerInjection[type]) { if (!providers[type]) { providers[type] = new providerInjection[type](); } - head.fn(providers[type]); + queue[i](providers[type]); continue; } - BI.Plugin.configWidget(type, head.fn); + BI.Plugin.configWidget(type, queue[i]); } configFunctions[type] = null; }); } - configFunctions[type].push({ - fn: configFn, - options: options - }) + configFunctions[type].push(configFn); }; var actions = {}; diff --git a/src/core/shortcut.js b/src/core/shortcut.js index 449b4cdff..26769de68 100644 --- a/src/core/shortcut.js +++ b/src/core/shortcut.js @@ -22,10 +22,7 @@ BI.createWidget = function (item, options, context) { // 先把准备环境准备好 - while (BI.prepares && BI.prepares.length > 0) { - BI.prepares.shift()(); - } - BI.initialized = true; + BI.init(); var el, w; item || (item = {}); if (BI.isWidget(options)) {