From eaaca33db2647474bcd93cbd1a4fdab7fc8e25bb Mon Sep 17 00:00:00 2001 From: Kira Date: Tue, 12 Nov 2019 00:11:37 +0800 Subject: [PATCH] =?UTF-8?q?KERNEL-1646=20refactor:=20=E5=8E=BB=E6=8E=89con?= =?UTF-8?q?fig=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 a79b4eca44..2dc4b7052b 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 afd03e3e73..30a15a2f8d 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 449b4cdffe..26769de686 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)) {