Browse Source

Pull request #2138: 无JIRA任务 config放get的时候执行

Merge in VISUAL/fineui from ~GUY/fineui:master to master

* commit 'ed05129bcfb27ed4a3169b1cda7144100c11e4b7':
  整理代码
  整理代码
  整理代码
  config放get的时候执行
es6
guy 3 years ago
parent
commit
0e4bc63d1e
  1. 74
      examples/config-render.html
  2. 111
      examples/dev.html
  3. 125
      examples/test-id.html
  4. 89
      examples/virtual-group.html
  5. 220
      examples/visible.html
  6. 18
      examples/插件设计.html
  7. 52
      src/core/4.widget.js
  8. 37
      src/core/5.shortcut.js
  9. 203
      src/core/6.inject.js
  10. 21
      src/core/7.plugin.js

74
examples/config-render.html

@ -0,0 +1,74 @@
<html>
<head>
<meta charset="utf-8">
<title></title>
<link rel="stylesheet" type="text/css" href="../dist/2.0/fineui.css"/>
<script src="../dist/2.0/fineui.js"></script>
</head>
<body>
<div id="wrapper"></div>
<script>
BI.Plugin.configRender("demo.parent", function (rendered) {
console.log(rendered);
return rendered;
});
var Widget = BI.inherit(BI.Widget, {
setup: function () {
var wrapper, list;
return function () {
return {
type: "bi.vertical",
items: [{
type: "bi.vertical",
invisible: true,
ref: function (_ref) {
wrapper = _ref;
},
items: [{
type: "bi.button_group",
height: 100,
ref: function (_ref) {
list = _ref;
},
items: [],
layouts: [{
type: "bi.inline",
tgap: 10,
lgap: 10
}]
}]
}, {
type: "bi.button",
text: "点击",
handler: function () {
list.populate(BI.range(10).map(function (i) {
return {
type: "bi.label",
text: i,
cls: "bi-border"
};
}));
wrapper.setVisible(true);
}
}]
};
};
}
});
BI.shortcut("demo.parent", Widget);
BI.createWidget({
type: "bi.absolute",
items: [{
el: {
type: "demo.parent"
},
top: 100,
left: 100
}],
element: "#wrapper"
});
</script>
</body>
</html>

111
examples/dev.html

@ -2,47 +2,96 @@
<head>
<meta charset="utf-8">
<title></title>
<link rel="stylesheet" type="text/css" href="../dist/2.0/fineui.css"/>
<!-- <script src="../dist/2.0/fineui.js"></script>-->
<script src="http://localhost:9001/fineui.js"></script>
<link rel="stylesheet" type="text/css" href="http://fanruan.design/fineui/2.0/fineui.min.css"/>
<script src="http://fanruan.design/fineui/2.0/fineui.min.js"></script>
</head>
<body>
<div id="wrapper"></div>
<script>
!(function () {
var Widget = BI.inherit(BI.Widget, {
props: {
vdom: true
},
watch: {
text: function () {
this.reset();
var element2InstanceMap = new WeakMap();
BI.getInstanceByElement = function (element) {
return element2InstanceMap.get(element);
};
BI.Plugin.config(function (options) {
}, function (shortcut, instance) {
instance.element.attr("shortcut", shortcut);
if (instance.options.$testId) {
setIDAttribute(instance.element[0], instance.options.$testId);
}
element2InstanceMap.set(instance.element[0], instance);
});
function setIDAttribute (element, id) {
if (element.id !== "") {
throw new Error("不能修改有默认id的元素");
}
element.setAttribute("id", id);
}
function registerWidgetIdGenerator () {
const idSet = new Set();
return function (shortcut, id) {
if (idSet.has(id)) {
throw new Error("id重复了");
}
idSet.add(id);
BI.Plugin.registerObject(shortcut, function (widget) {
setIDAttribute(widget.element[0], id);
});
};
}
BI.registerWidgetId = registerWidgetIdGenerator();
}());
</script>
<script>
function setTestId (parentShortcut, childShortcut, testId) {
BI.Plugin.configRender(parentShortcut, function (rendered) {
var queue = BI.isArray(rendered) ? rendered : [rendered];// 广度遍历
while (queue.length > 0) {
var element = queue.shift();
BI.each(element, function (key, value) {
if (BI.isArray(value)) {
queue = queue.concat(value);
} else if (BI.isPlainObject(value)) {
queue.push(value);
} else if ("type" === key && value === childShortcut) {
element.$testId = testId;
}
});
}
},
return rendered;
});
}
setTestId("demo.parent", "bi.button_group", "测试testId");
var Widget = BI.inherit(BI.Widget, {
setup: function () {
var list, count = 0;
var list;
return function () {
return {
type: "bi.vertical",
items: [{
type: "bi.virtual_group",
type: "bi.button_group",
height: 100,
ref: function (_ref) {
list = _ref;
},
items: BI.range(10).map(function (item, i) {
var r = {
items: BI.range(10).map(function (i) {
return {
type: "bi.label",
text: item,
// 指定key后,会根据key值进行前后两次数据对比,否则会根据数组索引进行数据对比
key: item,
text: i,
cls: "bi-border"
};
if (i === 9) {
r.width = "fill";
r.key = "唯一的标识";
}
return r;
}),
layouts: [{
type: "bi.inline",
@ -51,22 +100,8 @@
}]
}, {
type: "bi.button",
text: "点击删除第一个元素",
text: "点击",
handler: function () {
count++;
list.populate(BI.range(10 - count).map(function (i) {
var r = {
type: "bi.label",
text: i + count,
key: i + count,
cls: "bi-border"
};
if (i + count === 9) {
r.width = "fill";
r.key = "唯一的标识";
}
return r;
}));
}
}]
};

125
examples/test-id.html

@ -0,0 +1,125 @@
<html>
<head>
<meta charset="utf-8">
<title></title>
<link rel="stylesheet" type="text/css" href="../dist/2.0/fineui.css"/>
<script src="../dist/2.0/fineui.js"></script>
</head>
<body>
<div id="wrapper"></div>
<script>
!(function () {
var element2InstanceMap = new WeakMap();
BI.getInstanceByElement = function (element) {
return element2InstanceMap.get(element);
};
BI.Plugin.config(function (options) {
}, function (shortcut, instance) {
instance.element.attr("shortcut", shortcut);
if (instance.options.$testId) {
setIDAttribute(instance.element[0], instance.options.$testId);
}
element2InstanceMap.set(instance.element[0], instance);
});
function setIDAttribute (element, id) {
if (element.id !== "") {
throw new Error("不能修改有默认id的元素");
}
element.setAttribute("id", id);
}
function registerWidgetIdGenerator () {
const idSet = new Set();
return function (shortcut, id) {
if (idSet.has(id)) {
throw new Error("id重复了");
}
idSet.add(id);
BI.Plugin.registerObject(shortcut, function (widget) {
setIDAttribute(widget.element[0], id);
});
};
}
BI.registerWidgetId = registerWidgetIdGenerator();
}());
</script>
<script>
function setTestId (parentShortcut, childShortcut, testId) {
BI.Plugin.configRender(parentShortcut, function (rendered) {
var queue = BI.isArray(rendered) ? rendered : [rendered];// 广度遍历
while (queue.length > 0) {
var element = queue.shift();
BI.each(element, function (key, value) {
if (BI.isArray(value)) {
queue = queue.concat(value);
} else if (BI.isPlainObject(value)) {
queue.push(value);
} else if ("type" === key && value === childShortcut) {
element.$testId = testId;
}
});
}
return rendered;
});
}
setTestId("demo.parent", "bi.button_group", "测试testId");
var Widget = BI.inherit(BI.Widget, {
setup: function () {
var list;
return function () {
return {
type: "bi.vertical",
items: [{
type: "bi.button_group",
height: 100,
ref: function (_ref) {
list = _ref;
},
items: BI.range(10).map(function (i) {
return {
type: "bi.label",
text: i,
cls: "bi-border"
};
}),
layouts: [{
type: "bi.inline",
tgap: 10,
lgap: 10
}]
}, {
type: "bi.button",
text: "点击",
handler: function () {
}
}]
};
};
}
});
BI.shortcut("demo.parent", Widget);
BI.createWidget({
type: "bi.absolute",
items: [{
el: {
type: "demo.parent"
},
top: 100,
left: 100
}],
element: "#wrapper"
});
</script>
</body>
</html>

89
examples/virtual-group.html

@ -0,0 +1,89 @@
<html>
<head>
<meta charset="utf-8">
<title></title>
<link rel="stylesheet" type="text/css" href="../dist/2.0/fineui.css"/>
<script src="../dist/2.0/fineui.js"></script>
</head>
<body>
<div id="wrapper"></div>
<script>
var Widget = BI.inherit(BI.Widget, {
props: {
vdom: true
},
watch: {
text: function () {
this.reset();
}
},
setup: function () {
var list, count = 0;
return function () {
return {
type: "bi.vertical",
items: [{
type: "bi.virtual_group",
height: 100,
ref: function (_ref) {
list = _ref;
},
items: BI.range(10).map(function (item, i) {
var r = {
type: "bi.label",
text: item,
// 指定key后,会根据key值进行前后两次数据对比,否则会根据数组索引进行数据对比
key: item,
cls: "bi-border"
};
if (i === 9) {
r.width = "fill";
r.key = "唯一的标识";
}
return r;
}),
layouts: [{
type: "bi.inline",
tgap: 10,
lgap: 10
}]
}, {
type: "bi.button",
text: "点击删除第一个元素",
handler: function () {
count++;
list.populate(BI.range(10 - count).map(function (i) {
var r = {
type: "bi.label",
text: i + count,
key: i + count,
cls: "bi-border"
};
if (i + count === 9) {
r.width = "fill";
r.key = "唯一的标识";
}
return r;
}));
}
}]
};
};
}
});
BI.shortcut("demo.parent", Widget);
BI.createWidget({
type: "bi.absolute",
items: [{
el: {
type: "demo.parent"
},
top: 100,
left: 100
}],
element: "#wrapper"
});
</script>
</body>
</html>

220
examples/visible.html

@ -0,0 +1,220 @@
<html>
<head>
<meta charset="utf-8">
<title></title>
<link rel="stylesheet" type="text/css" href="../dist/2.0/fineui.css"/>
<script src="../dist/2.0/fineui.js"></script>
</head>
<body>
<div id="wrapper"></div>
<script>
var Item = BI.inherit(BI.BasicButton, {
props: {
baseCls: "bi-list-item-active"
},
render: function () {
var self = this;
return {
type: "bi.vertical_adapt",
items: [
{
el: {
type: "bi.label",
textAlign: "left",
text: this.options.text
},
lgap: this.options.layer * 24 + 24
}
]
};
},
getValue: function () {
return this.options.id;
}
});
BI.shortcut("bi.example.single_custom_tree.item", Item);
var Node = BI.inherit(BI.NodeButton, {
props: {
baseCls: "bi-list-item"
},
render: function () {
var self = this;
return {
type: "bi.vertical_adapt",
items: [
{
el: {
type: "bi.label",
ref: function (_ref) {
self.icon = _ref;
},
text: this.options.open ? "-" : "+",
height: 24,
width: 24
},
lgap: this.options.layer * 24
}, {
type: "bi.label",
textAlign: "left",
text: this.options.text
}
]
};
},
setOpened: function (b) {
Node.superclass.setOpened.apply(this, arguments);
this.icon.setText(b ? "-" : "+");
},
getValue: function () {
return this.options.id;
}
});
BI.shortcut("bi.example.single_custom_tree.node", Node);
var mockData = [
{
id: "无锡",
text: "无锡",
isParent: true
}, {
id: "锡山区",
text: "锡山区",
pId: "无锡",
isParent: true
}, {
id: "安镇街道",
text: "安镇街道",
pId: "锡山区"
}, {
id: "滨湖区",
text: "滨湖区",
pId: "无锡"
}, {
id: "南京",
text: "南京",
isParent: true
}, {
id: "建邺区",
text: "建邺区",
pId: "南京"
}
];
var Tree = BI.inherit(BI.Widget, {
render: function () {
var self = this;
return {
type: "bi.custom_tree",
ref: function (_ref) {
self.tree = _ref;
},
expander: {
type: "bi.expander",
isDefaultInit: false,
el: {},
popup: {
type: "bi.custom_tree"
}
},
el: {
type: "bi.button_tree",
chooseType: 0,
layouts: [
{
type: "bi.vertical"
}
]
},
items: []
};
},
_formatItems: function (items) {
var nodes = BI.map(items, function (index, item) {
return BI.extend({
type: item.isParent ? "bi.example.single_custom_tree.node" : "bi.example.single_custom_tree.item"
}, item);
});
return this.traversalLayers(BI.Tree.transformToTreeFormat(nodes), 0);
},
traversalLayers: function (items, layer) {
var self = this;
BI.each(items, function (index, item) {
item.layer = layer;
if (item.children) {
self.traversalLayers(item.children, layer + 1);
}
});
return items;
},
populate: function (items) {
this.tree.populate(this._formatItems(items));
}
});
BI.shortcut("bi.example.single_custom_tree", Tree);
var Widget = BI.inherit(BI.Widget, {
setup: function () {
var wrapper, tree;
return function () {
return {
type: "bi.vertical",
items: [{
type: "bi.vertical",
invisible: true,
ref: function (_ref) {
wrapper = _ref;
},
items: [{
type: "bi.example.single_custom_tree",
height: 100,
ref: function (_ref) {
tree = _ref;
}
}]
}, {
type: "bi.button",
text: "点击",
handler: function () {
tree.populate(mockData);
wrapper.setVisible(true);
}
}]
};
};
}
});
BI.shortcut("demo.parent", Widget);
BI.createWidget({
type: "bi.absolute",
items: [{
el: {
type: "demo.parent"
},
top: 100,
left: 100
}],
element: "#wrapper"
});
</script>
</body>
</html>

18
examples/插件设计.html

@ -3,15 +3,19 @@
<meta charset="utf-8">
<title></title>
<link rel="stylesheet" type="text/css" href="../dist/2.0/fineui.css"/>
<!-- <script src="../dist/2.0/fineui.js"></script>-->
<script src="http://localhost:9001/fineui.js"></script>
<script src="../dist/2.0/fineui.js"></script>
<!-- <link rel="stylesheet" type="text/css" href="http://fanruan.design/fineui/2.0/fineui.min.css" />-->
<!-- <script src="http://fanruan.design/fineui/2.0/fineui.min.js"></script>-->
</head>
<body>
<div id="wrapper"></div>
<script>
BI.config("demo.parent", function (config){
BI.config("demo.parent", function (config) {
console.log("123");
return config;
return {
type: "bi.button",
text: "被替换的组件"
};
}, {
version: "1.0"
});
@ -22,7 +26,7 @@
components: {
"demo.parent": "1.0"
}
})
});
// 主线代码里加这个
BI.config("bi.provider.system", function (provider) {
@ -31,8 +35,8 @@
minVersion: "2.0",
maxVersion: "4.0"
}
})
})
});
});
</script>
<script>
var Model = BI.inherit(Fix.Model, {

52
src/core/4.widget.js

@ -114,6 +114,7 @@
return;
}
initCallbackCalled = true;
function render () {
// 加个保险
if (renderCallbackCalled === true) {
@ -123,6 +124,7 @@
renderCallbackCalled = true;
self._render();
}
if (self.options.beforeRender || self.beforeRender) {
self.__async = true;
(self.options.beforeRender || self.beforeRender).call(self, render);
@ -235,27 +237,14 @@
var self = this;
var isMounted = this._isMounted;
this.__async === true && isMounted && callLifeHook(this, "beforeMount");
var render = BI.isFunction(this.options.render) ? this.options.render : this.render;
var els = render && render.call(this);
if (BI.isPlainObject(els)) {
els = [els];
}
if (BI.isArray(els)) {
if (this.options.vdom) {
var div = document.createElement("div");
var element = this.element;
element.append(div);
this.vnode = this._renderVNode();
BI.patchVNode(div, this.vnode);
// 去除这个临时的div
BI.DOM.hang([div]);
element.attr("style", self.vnode.elm.getAttribute("style"));
element.addClass(self.vnode.elm.getAttribute("class"));
element.empty();
BI.each(BI.jQuery(self.vnode.elm).children(), function (i, node) {
element.append(node);
});
} else {
if (!this._initVNode()) {
var render = BI.isFunction(this.options.render) ? this.options.render : this.render;
var els = render && render.call(this);
els = BI.Plugin.getRender(this.options.type, els);
if (BI.isPlainObject(els)) {
els = [els];
}
if (BI.isArray(els)) {
BI.each(els, function (i, el) {
if (el) {
BI._lazyCreateWidget(el, {
@ -272,10 +261,31 @@
}
},
_initVNode: function () {
if (this.options.vdom) {
var div = document.createElement("div");
var element = this.element;
element.append(div);
this.vnode = this._renderVNode();
BI.patchVNode(div, this.vnode);
// 去除这个临时的div
BI.DOM.hang([div]);
element.attr("style", self.vnode.elm.getAttribute("style"));
element.addClass(self.vnode.elm.getAttribute("class"));
element.empty();
BI.each(BI.jQuery(self.vnode.elm).children(), function (i, node) {
element.append(node);
});
return true;
}
return false;
},
_renderVNode: function () {
var self = this;
var render = BI.isFunction(this.options.render) ? this.options.render : this.render;
var els = render && render.call(this);
els = BI.Plugin.getRender(this.options.type, els);
if (BI.isPlainObject(els)) {
els = [els];
}

37
src/core/5.shortcut.js

@ -35,9 +35,6 @@
};
BI.createWidget = BI.createWidget || function (item, options, context, lazy) {
// 先把准备环境准备好
BI.init();
var el, w;
item || (item = {});
if (BI.isWidget(options)) {
context = options;
@ -45,6 +42,21 @@
} else {
options || (options = {});
}
var el, w;
if (item.type || options.type) {
el = BI.extend({}, options, item);
} else if (item.el && (item.el.type || options.type)) {
el = BI.extend({}, options, item.el);
}
if (el) {
BI.runConfigFunction(el.type);
}
// 先把准备环境准备好
BI.init();
if (BI.isEmpty(item) && BI.isEmpty(options)) {
return BI.createWidget({
type: "bi.layout"
@ -53,24 +65,7 @@
if (BI.isWidget(item)) {
return item;
}
if (item.type || options.type) {
el = BI.extend({}, options, item);
w = BI.Plugin.getWidget(el.type, el);
if (w.type === el.type) {
if (BI.Plugin.hasObject(el.type)) {
w.listeners = (w.listeners || []).concat([{
eventName: BI.Events.MOUNT,
action: function () {
BI.Plugin.getObject(el.type, this);
}
}]);
}
return createWidget(w, context, lazy);
}
return BI.createWidget(w, options, context, lazy);
}
if (item.el && (item.el.type || options.type)) {
el = BI.extend({}, options, item.el);
if (el) {
w = BI.Plugin.getWidget(el.type, el);
if (w.type === el.type) {
if (BI.Plugin.hasObject(el.type)) {

203
src/core/6.inject.js

@ -74,85 +74,163 @@
};
var configFunctions = {};
BI.config = BI.config || function (type, configFn, opt) {
opt = opt || {};
// 初始化过或者系统配置需要立刻执行
if (BI.initialized || "bi.provider.system" === type) {
var runConfigFunction = BI.runConfigFunction = function (type) {
if (!type || !configFunctions[type]) {
return false;
}
var queue = configFunctions[type];
delete configFunctions[type];
var dependencies = BI.Providers.getProvider("bi.provider.system").getDependencies();
var modules = moduleInjectionMap.components[type]
|| moduleInjectionMap.constants[type]
|| moduleInjectionMap.services[type]
|| moduleInjectionMap.stores[type]
|| moduleInjectionMap.models[type]
|| moduleInjectionMap.providers[type];
for (var i = 0; i < queue.length; i++) {
var conf = queue[i];
var version = conf.opt.version;
var fn = conf.fn;
if (modules && version) {
var findVersion = false;
for (var j = 0; j < modules.length; j++) {
var module = modules[j];
if (module && dependencies[module.moduleId] && module.version === version) {
var minVersion = dependencies[module.moduleId].minVersion,
maxVersion = dependencies[module.moduleId].maxVersion;
if (minVersion && (moduleInjection[module.moduleId].version || version) < minVersion) {
findVersion = true;
break;
}
if (maxVersion && (moduleInjection[module.moduleId].version || version) > maxVersion) {
findVersion = true;
break;
}
}
}
if (findVersion === true) {
_global.console && console.error("moduleId: [" + module.moduleId + "] 接口: [" + type + "] 接口版本: [" + version + "] 已过期,版本要求为:", dependencies[module.moduleId], "=>", moduleInjection[module.moduleId]);
continue;
}
}
if (constantInjection[type]) {
return (constantInjection[type] = configFn(constantInjection[type]));
constantInjection[type] = fn(constantInjection[type]);
continue;
}
if (providerInjection[type]) {
if (!providers[type]) {
providers[type] = new providerInjection[type]();
}
// 如果config被重新配置的话,需要删除掉之前的实例
if (providerInstance[type]) {
delete providerInstance[type];
}
return configFn(providers[type]);
fn(providers[type]);
continue;
}
BI.Plugin.configWidget(type, fn);
}
};
BI.config = BI.config || function (type, configFn, opt) {
opt = opt || {};
// 系统配置直接执行
if ("bi.provider.system" === type) {
if (!providers[type]) {
providers[type] = new providerInjection[type]();
}
// 如果config被重新配置的话,需要删除掉之前的实例
if (providerInstance[type]) {
delete providerInstance[type];
}
return BI.Plugin.configWidget(type, configFn, opt);
return configFn(providers[type]);
}
if (!configFunctions[type]) {
configFunctions[type] = [];
BI.prepares.push(function () {
var queue = configFunctions[type];
var dependencies = BI.Providers.getProvider("bi.provider.system").getDependencies();
var modules = moduleInjectionMap.components[type]
|| moduleInjectionMap.constants[type]
|| moduleInjectionMap.services[type]
|| moduleInjectionMap.stores[type]
|| moduleInjectionMap.models[type]
|| moduleInjectionMap.providers[type];
for (var i = 0; i < queue.length; i++) {
var conf = queue[i];
var version = conf.opt.version;
var fn = conf.fn;
if (modules && version) {
var findVersion = false;
for (var j = 0; j < modules.length; j++) {
var module = modules[i];
if (module && dependencies[module.moduleId] && module.version === version) {
var minVersion = dependencies[module.moduleId].minVersion,
maxVersion = dependencies[module.moduleId].maxVersion;
if (minVersion && (moduleInjection[module.moduleId].version || version) < minVersion) {
findVersion = true;
break;
}
if (maxVersion && (moduleInjection[module.moduleId].version || version) > maxVersion) {
findVersion = true;
break;
}
}
}
if (findVersion === true) {
_global.console && console.error("moduleId: [" + module.moduleId + "] 接口: [" + type + "] 接口版本: [" + version + "] 已过期,版本要求为:", dependencies[module.moduleId], "=>", moduleInjection[module.moduleId]);
continue;
}
}
if (constantInjection[type]) {
constantInjection[type] = fn(constantInjection[type]);
continue;
}
if (providerInjection[type]) {
if (!providers[type]) {
providers[type] = new providerInjection[type]();
}
if (providerInstance[type]) {
delete providerInstance[type];
}
fn(providers[type]);
continue;
}
BI.Plugin.configWidget(type, fn);
}
configFunctions[type] = null;
});
}
configFunctions[type].push({
fn: configFn,
opt: opt
});
// // 初始化过或者系统配置需要立刻执行
// if (BI.initialized || "bi.provider.system" === type) {
// 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];
// var dependencies = BI.Providers.getProvider("bi.provider.system").getDependencies();
// var modules = moduleInjectionMap.components[type]
// || moduleInjectionMap.constants[type]
// || moduleInjectionMap.services[type]
// || moduleInjectionMap.stores[type]
// || moduleInjectionMap.models[type]
// || moduleInjectionMap.providers[type];
// for (var i = 0; i < queue.length; i++) {
// var conf = queue[i];
// var version = conf.opt.version;
// var fn = conf.fn;
// if (modules && version) {
// var findVersion = false;
// for (var j = 0; j < modules.length; j++) {
// var module = modules[i];
// if (module && dependencies[module.moduleId] && module.version === version) {
// var minVersion = dependencies[module.moduleId].minVersion,
// maxVersion = dependencies[module.moduleId].maxVersion;
// if (minVersion && (moduleInjection[module.moduleId].version || version) < minVersion) {
// findVersion = true;
// break;
// }
// if (maxVersion && (moduleInjection[module.moduleId].version || version) > maxVersion) {
// findVersion = true;
// break;
// }
// }
// }
// if (findVersion === true) {
// _global.console && console.error("moduleId: [" + module.moduleId + "] 接口: [" + type + "] 接口版本: [" + version + "] 已过期,版本要求为:", dependencies[module.moduleId], "=>", moduleInjection[module.moduleId]);
// continue;
// }
// }
// if (constantInjection[type]) {
// constantInjection[type] = fn(constantInjection[type]);
// continue;
// }
// if (providerInjection[type]) {
// if (!providers[type]) {
// providers[type] = new providerInjection[type]();
// }
// if (providerInstance[type]) {
// delete providerInstance[type];
// }
// fn(providers[type]);
// continue;
// }
// BI.Plugin.configWidget(type, fn);
// }
// configFunctions[type] = null;
// });
// }
// configFunctions[type].push({
// fn: configFn,
// opt: opt
// });
};
BI.getReference = BI.getReference || function (type, fn) {
@ -215,6 +293,7 @@
if (BI.isNull(constantInjection[type])) {
_global.console && console.error("constant: [" + type + "] 未定义");
}
runConfigFunction(type);
return constantInjection[type];
}
};
@ -262,6 +341,7 @@
if (!modelInjection[type]) {
_global.console && console.error("model: [" + type + "] 未定义");
}
runConfigFunction(type);
var inst = new modelInjection[type](config);
inst._constructor && inst._constructor(config);
inst.mixins && callPoint(inst, inst.mixins);
@ -313,6 +393,7 @@
if (!providerInjection[type]) {
_global.console && console.error("provider: [" + type + "] 未定义");
}
runConfigFunction(type);
if (!providers[type]) {
providers[type] = new providerInjection[type]();
}

21
src/core/7.plugin.js

@ -3,6 +3,7 @@ BI.Plugin = BI.Plugin || {};
var _WidgetsPlugin = {};
var _ObjectPlugin = {};
var _ConfigPlugin = {};
var _ConfigRenderPlugin = {};
var _GlobalWidgetConfigFns = [];
var __GlobalObjectConfigFns = [];
BI.defaults(BI.Plugin, {
@ -47,6 +48,25 @@ BI.Plugin = BI.Plugin || {};
_ConfigPlugin[type].push(fn);
},
getRender: function (type, rendered) {
var res;
if (_ConfigRenderPlugin[type]) {
for (var i = _ConfigRenderPlugin[type].length - 1; i >= 0; i--) {
if (res = _ConfigRenderPlugin[type][i](rendered)) {
rendered = res;
}
}
}
return rendered;
},
configRender: function (type, fn) {
if (!_ConfigRenderPlugin[type]) {
_ConfigRenderPlugin[type] = [];
}
_ConfigRenderPlugin[type].push(fn);
},
// Deprecated
registerWidget: function (type, fn) {
if (!_WidgetsPlugin[type]) {
@ -58,6 +78,7 @@ BI.Plugin = BI.Plugin || {};
_WidgetsPlugin[type].push(fn);
},
// Deprecated
relieveWidget: function (type) {
delete _WidgetsPlugin[type];
},

Loading…
Cancel
Save