guy 3 years ago
parent
commit
ba2a96ac1d
  1. 6
      src/core/5.shortcut.js
  2. 31
      src/core/6.inject.js

6
src/core/5.shortcut.js

@ -2,7 +2,7 @@
var kv = {}; var kv = {};
BI.shortcut = BI.component = BI.shortcut || function (xtype, cls) { BI.shortcut = BI.component = BI.shortcut || function (xtype, cls) {
if (kv[xtype] != null) { if (kv[xtype] != null) {
_global.console && console.error("shortcut:[" + xtype + "] has been registed"); _global.console && console.error("组件: [" + xtype + "] 已经注册过了");
} }
if (cls) { if (cls) {
cls["xtype"] = xtype; cls["xtype"] = xtype;
@ -15,7 +15,7 @@
var cls = kv[config.type]; var cls = kv[config.type];
if (!cls) { if (!cls) {
throw new Error("组件" + config.type + "未定义"); throw new Error("组件: [" + config.type + "] 未定义");
} }
var pushed = false; var pushed = false;
var widget = new cls(); var widget = new cls();
@ -88,7 +88,7 @@
if (BI.isWidget(item.el)) { if (BI.isWidget(item.el)) {
return item.el; return item.el;
} }
throw new Error("无法根据item创建组件"); throw new Error("组件创建:无法根据item创建组件", item);
}; };
BI._lazyCreateWidget = BI._lazyCreateWidget || function (item, options, context) { BI._lazyCreateWidget = BI._lazyCreateWidget || function (item, options, context) {

31
src/core/6.inject.js

@ -2,7 +2,7 @@
var moduleInjection = {}; var moduleInjection = {};
BI.module = BI.module || function (xtype, cls) { BI.module = BI.module || function (xtype, cls) {
if (moduleInjection[xtype] != null) { if (moduleInjection[xtype] != null) {
_global.console && console.error("module:[" + xtype + "] has been registed"); _global.console && console.error("module[" + xtype + "] 已经注册过了");
} }
moduleInjection[xtype] = cls; moduleInjection[xtype] = cls;
}; };
@ -10,7 +10,7 @@
var constantInjection = {}; var constantInjection = {};
BI.constant = BI.constant || function (xtype, cls) { BI.constant = BI.constant || function (xtype, cls) {
if (constantInjection[xtype] != null) { if (constantInjection[xtype] != null) {
_global.console && console.error("constant:[" + xtype + "] has been registed"); _global.console && console.error("constant: [" + xtype + "]已经注册过了");
} }
constantInjection[xtype] = cls; constantInjection[xtype] = cls;
}; };
@ -18,7 +18,7 @@
var modelInjection = {}; var modelInjection = {};
BI.model = BI.model || function (xtype, cls) { BI.model = BI.model || function (xtype, cls) {
if (modelInjection[xtype] != null) { if (modelInjection[xtype] != null) {
_global.console && console.error("model:[" + xtype + "] has been registed"); _global.console && console.error("model: [" + xtype + "] 已经注册过了");
} }
modelInjection[xtype] = cls; modelInjection[xtype] = cls;
}; };
@ -26,7 +26,7 @@
var storeInjection = {}; var storeInjection = {};
BI.store = BI.store || function (xtype, cls) { BI.store = BI.store || function (xtype, cls) {
if (storeInjection[xtype] != null) { if (storeInjection[xtype] != null) {
_global.console && console.error("store:[" + xtype + "] has been registed"); _global.console && console.error("store: [" + xtype + "] 已经注册过了");
} }
storeInjection[xtype] = cls; storeInjection[xtype] = cls;
}; };
@ -34,7 +34,7 @@
var serviceInjection = {}; var serviceInjection = {};
BI.service = BI.service || function (xtype, cls) { BI.service = BI.service || function (xtype, cls) {
if (serviceInjection[xtype] != null) { if (serviceInjection[xtype] != null) {
_global.console && console.error("service:[" + xtype + "] has been registed"); _global.console && console.error("service: [" + xtype + "] 已经注册过了");
} }
serviceInjection[xtype] = cls; serviceInjection[xtype] = cls;
}; };
@ -42,7 +42,7 @@
var providerInjection = {}; var providerInjection = {};
BI.provider = BI.provider || function (xtype, cls) { BI.provider = BI.provider || function (xtype, cls) {
if (providerInjection[xtype] != null) { if (providerInjection[xtype] != null) {
_global.console && console.error("provider:[" + xtype + "] has been registed"); _global.console && console.error("provider: [" + xtype + "] 已经注册过了");
} }
providerInjection[xtype] = cls; providerInjection[xtype] = cls;
}; };
@ -138,8 +138,7 @@
BI.Modules = BI.Modules || { BI.Modules = BI.Modules || {
getModule: function (type) { getModule: function (type) {
if (!moduleInjection[type]) { if (!moduleInjection[type]) {
_global.console && console.error("module:[" + type + "] does not exists"); throw new Error("module: [" + type + "] 未定义");
return false;
} }
return moduleInjection[type]; return moduleInjection[type];
}, },
@ -150,6 +149,9 @@
BI.Constants = BI.Constants || { BI.Constants = BI.Constants || {
getConstant: function (type) { getConstant: function (type) {
if (!constantInjection[type]) {
throw new Error("constant: [" + type + "] 未定义");
}
return constantInjection[type]; return constantInjection[type];
} }
}; };
@ -194,6 +196,9 @@
BI.Models = BI.Models || { BI.Models = BI.Models || {
getModel: function (type, config) { getModel: function (type, config) {
if (!modelInjection[type]) {
throw new Error("model: [" + type + "] 未定义");
}
var inst = new modelInjection[type](config); var inst = new modelInjection[type](config);
inst._constructor && inst._constructor(config); inst._constructor && inst._constructor(config);
inst.mixins && callPoint(inst, inst.mixins); inst.mixins && callPoint(inst, inst.mixins);
@ -206,6 +211,9 @@
BI.Stores = BI.Stores || { BI.Stores = BI.Stores || {
getStore: function (type, config) { getStore: function (type, config) {
if (!storeInjection[type]) {
throw new Error("store: [" + type + "] 未定义");
}
if (stores[type]) { if (stores[type]) {
return stores[type]; return stores[type];
} }
@ -222,6 +230,9 @@
BI.Services = BI.Services || { BI.Services = BI.Services || {
getService: function (type, config) { getService: function (type, config) {
if (!serviceInjection[type]) {
throw new Error("service: [" + type + "] 未定义");
}
if (services[type]) { if (services[type]) {
return services[type]; return services[type];
} }
@ -236,6 +247,9 @@
BI.Providers = BI.Providers || { BI.Providers = BI.Providers || {
getProvider: function (type, config) { getProvider: function (type, config) {
if (!providerInjection[type]) {
throw new Error("provider: [" + type + "] 未定义");
}
if (!providers[type]) { if (!providers[type]) {
providers[type] = new providerInjection[type](); providers[type] = new providerInjection[type]();
} }
@ -284,5 +298,6 @@
if (providerInjection[type]) { if (providerInjection[type]) {
return BI.Providers.getProvider(type, config); return BI.Providers.getProvider(type, config);
} }
throw new Error("未知类型: [" + type + "] 未定义");
}; };
})(); })();

Loading…
Cancel
Save