Browse Source

KERNEL-1646 refactor: config可配置参数屏蔽掉之前注册的插件,inject放到第一次createWidget时做

es6
Kira 5 years ago
parent
commit
54c204c74e
  1. 59
      src/core/inject.js
  2. 11
      src/core/plugin.js
  3. 1
      src/core/shortcut.js

59
src/core/inject.js

@ -47,17 +47,53 @@
providerInjection[xtype] = cls; providerInjection[xtype] = cls;
}; };
BI.config = function (type, configFn) { var configFunctions = {};
if (constantInjection[type]) { BI.config = function (type, configFn, options) {
return constantInjection[type] = configFn(constantInjection[type]); if (BI.initialize) {
} if (constantInjection[type]) {
if (providerInjection[type]) { return (constantInjection[type] = configFn(constantInjection[type]));
if (!providers[type]) {
providers[type] = new providerInjection[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 = {}; var actions = {};
@ -189,7 +225,8 @@
} }
}; };
var providers = {}, providerInstance = {}; var providers = {},
providerInstance = {};
BI.Providers = { BI.Providers = {
getProvider: function (type, config) { getProvider: function (type, config) {
@ -242,4 +279,4 @@
return BI.Providers.getProvider(type, config); return BI.Providers.getProvider(type, config);
} }
}; };
})(); })();

11
src/core/plugin.js

@ -10,13 +10,16 @@ BI.Plugin = BI.Plugin || {};
if (_GlobalWidgetConfigFn) { if (_GlobalWidgetConfigFn) {
_GlobalWidgetConfigFn(type, options); _GlobalWidgetConfigFn(type, options);
} }
var res;
if (_ConfigPlugin[type]) { if (_ConfigPlugin[type]) {
for (var i = _ConfigPlugin[type].length - 1; i >= 0; i--) { 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]) { if (_WidgetsPlugin[type]) {
var res;
for (var i = _WidgetsPlugin[type].length - 1; i >= 0; i--) { for (var i = _WidgetsPlugin[type].length - 1; i >= 0; i--) {
if (res = _WidgetsPlugin[type][i](options)) { if (res = _WidgetsPlugin[type][i](options)) {
return res; return res;
@ -59,7 +62,9 @@ BI.Plugin = BI.Plugin || {};
if (_ObjectPlugin[type]) { if (_ObjectPlugin[type]) {
var res; var res;
for (var i = 0, len = _ObjectPlugin[type].length; i < len; i++) { 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; return res || object;

1
src/core/shortcut.js

@ -25,6 +25,7 @@
while (BI.prepares && BI.prepares.length > 0) { while (BI.prepares && BI.prepares.length > 0) {
BI.prepares.shift()(); BI.prepares.shift()();
} }
BI.initialize = true;
var el, w; var el, w;
item || (item = {}); item || (item = {});
if (BI.isWidget(options)) { if (BI.isWidget(options)) {

Loading…
Cancel
Save