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 3233b98ac..30a15a2f8 100644 --- a/src/core/inject.js +++ b/src/core/inject.js @@ -47,17 +47,42 @@ providerInjection[xtype] = cls; }; + var configFunctions = {}; 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](); + if (BI.initialized) { + 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 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](); + } + queue[i](providers[type]); + continue; + } + BI.Plugin.configWidget(type, queue[i]); + } + configFunctions[type] = null; + }); } - BI.Plugin.configWidget(type, configFn); + configFunctions[type].push(configFn); }; var actions = {}; @@ -189,7 +214,8 @@ } }; - var providers = {}, providerInstance = {}; + var providers = {}, + providerInstance = {}; BI.Providers = { getProvider: function (type, config) { @@ -242,4 +268,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..26769de68 100644 --- a/src/core/shortcut.js +++ b/src/core/shortcut.js @@ -22,9 +22,7 @@ BI.createWidget = function (item, options, context) { // 先把准备环境准备好 - while (BI.prepares && BI.prepares.length > 0) { - BI.prepares.shift()(); - } + BI.init(); var el, w; item || (item = {}); if (BI.isWidget(options)) {