From dee2daa1ec09b7fed3b521e1972ab44966639061 Mon Sep 17 00:00:00 2001 From: windy <1374721899@qq.com> Date: Mon, 7 Dec 2020 10:46:33 +0800 Subject: [PATCH] =?UTF-8?q?=E6=97=A0JIRA=E4=BB=BB=E5=8A=A1=20=E5=9B=9E?= =?UTF-8?q?=E6=BB=9ABI.config=E7=9A=84=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core/inject.js | 83 ++++++++++++-------------------------------- src/core/shortcut.js | 13 ------- 2 files changed, 23 insertions(+), 73 deletions(-) diff --git a/src/core/inject.js b/src/core/inject.js index fe09a0ca5..13e9f9e4c 100644 --- a/src/core/inject.js +++ b/src/core/inject.js @@ -49,7 +49,7 @@ var configFunctions = {}; BI.config = BI.config || function (type, configFn, opt) { - if (opt && opt.immediate) { + if (BI.initialized) { if (constantInjection[type]) { return (constantInjection[type] = configFn(constantInjection[type])); } @@ -67,49 +67,29 @@ } if (!configFunctions[type]) { configFunctions[type] = []; + BI.prepares.push(function () { + var queue = configFunctions[type]; + for (var i = 0; i < queue.length; i++) { + if (constantInjection[type]) { + constantInjection[type] = queue[i](constantInjection[type]); + continue; + } + if (providerInjection[type]) { + if (!providers[type]) { + providers[type] = new providerInjection[type](); + } + if (providerInstance[type]) { + delete providerInstance[type]; + } + queue[i](providers[type]); + continue; + } + BI.Plugin.configWidget(type, queue[i]); + } + configFunctions[type] = null; + }); } configFunctions[type].push({fn: configFn, args: opt}); - // if (BI.initialized) { - // if (constantInjection[type]) { - // return (constantInjection[type] = configFn(constantInjection[type])); - // } - // if (providerInjection[type]) { - // if (!providers[type]) { - // providers[type] = new providerInjection[type](); - // } - // // 如果config被重新配置的话,需要删除掉之前的实例 - // if (providerInstance[type]) { - // delete providerInstance[type]; - // } - // return configFn(providers[type]); - // } - // return BI.Plugin.configWidget(type, configFn, opt); - // } - // if (!configFunctions[type]) { - // configFunctions[type] = []; - // BI.prepares.push(function () { - // var queue = configFunctions[type]; - // for (var i = 0; i < queue.length; i++) { - // if (constantInjection[type]) { - // constantInjection[type] = queue[i](constantInjection[type]); - // continue; - // } - // if (providerInjection[type]) { - // if (!providers[type]) { - // providers[type] = new providerInjection[type](); - // } - // if (providerInstance[type]) { - // delete providerInstance[type]; - // } - // queue[i](providers[type]); - // continue; - // } - // BI.Plugin.configWidget(type, queue[i]); - // } - // configFunctions[type] = null; - // }); - // } - // configFunctions[type].push(configFn); }; BI.Configs = BI.Configs || { @@ -175,16 +155,7 @@ BI.Constants = BI.Constants || { getConstant: function (type) { - var instance = constantInjection[type]; - BI.each(configFunctions[type], function (i, cf) { - var res = cf.fn(instance); - if (res) { - instance = res; - } - }); - constantInjection[type] = instance; - configFunctions[type] && (configFunctions[type] = null); - return instance; + return constantInjection[type]; } }; @@ -273,17 +244,9 @@ if (!providers[type]) { providers[type] = new providerInjection[type](); } - var instance = providers[type]; - BI.each(configFunctions[type], function (i, cf) { - if (providerInstance[type]) { - delete providerInstance[type]; - } - cf.fn(instance); - }); if (!providerInstance[type]) { providerInstance[type] = new (providers[type].$get())(config); } - configFunctions[type] && (configFunctions[type] = null); return providerInstance[type]; } }; diff --git a/src/core/shortcut.js b/src/core/shortcut.js index 1a6568662..001a73b8c 100644 --- a/src/core/shortcut.js +++ b/src/core/shortcut.js @@ -32,17 +32,6 @@ return widget; }; - function configWidget (type) { - var configFunctions = BI.Configs.getConfig(type); - if (configFunctions) { - BI.each(configFunctions, function (i, cf) { - BI.Plugin.configWidget(type, cf.fn, cf.args); - }); - var configs = BI.Configs.getConfigs(); - configs[type] && (configs[type] = null); - } - } - BI.createWidget = BI.createWidget || function (item, options, context, lazy) { // 先把准备环境准备好 BI.init(); @@ -64,7 +53,6 @@ } if (item.type || options.type) { el = BI.extend({}, options, item); - configWidget(el.type); w = BI.Plugin.getWidget(el.type, el); w.listeners = (w.listeners || []).concat([{ eventName: BI.Events.MOUNT, @@ -76,7 +64,6 @@ } if (item.el && (item.el.type || options.type)) { el = BI.extend({}, options, item.el); - configWidget(el.type); w = BI.Plugin.getWidget(el.type, el); w.listeners = (w.listeners || []).concat([{ eventName: BI.Events.MOUNT,