forked from fanruan/fineui
Zhenfei.Li
2 years ago
8 changed files with 330 additions and 298 deletions
@ -1,123 +1,127 @@ |
|||||||
BI.Plugin = BI.Plugin || {}; |
const _WidgetsPlugin = {}; |
||||||
!(function () { |
const _ObjectPlugin = {}; |
||||||
var _WidgetsPlugin = {}; |
const _ConfigPlugin = {}; |
||||||
var _ObjectPlugin = {}; |
const _ConfigRenderPlugin = {}; |
||||||
var _ConfigPlugin = {}; |
let _GlobalWidgetConfigFns = []; |
||||||
var _ConfigRenderPlugin = {}; |
let __GlobalObjectConfigFns = []; |
||||||
var _GlobalWidgetConfigFns = []; |
|
||||||
var __GlobalObjectConfigFns = []; |
|
||||||
BI.defaults(BI.Plugin, { |
|
||||||
|
|
||||||
getWidget: function (type, options) { |
export const Plugin = { |
||||||
if (_GlobalWidgetConfigFns.length > 0) { |
getWidget (type, options) { |
||||||
var fns = _GlobalWidgetConfigFns.slice(0); |
if (_GlobalWidgetConfigFns.length > 0) { |
||||||
for (var i = fns.length - 1; i >= 0; i--) { |
const fns = _GlobalWidgetConfigFns.slice(0); |
||||||
fns[i](type, options); |
for (let i = fns.length - 1; i >= 0; i--) { |
||||||
} |
fns[i](type, options); |
||||||
} |
} |
||||||
|
} |
||||||
|
|
||||||
var res; |
let res; |
||||||
if (_ConfigPlugin[type]) { |
if (_ConfigPlugin[type]) { |
||||||
for (var i = _ConfigPlugin[type].length - 1; i >= 0; i--) { |
for (let i = _ConfigPlugin[type].length - 1; i >= 0; i--) { |
||||||
if (res = _ConfigPlugin[type][i](options)) { |
res = _ConfigPlugin[type][i](options); |
||||||
options = res; |
if (res) { |
||||||
} |
options = res; |
||||||
} |
} |
||||||
} |
} |
||||||
// Deprecated
|
} |
||||||
if (_WidgetsPlugin[type]) { |
// Deprecated
|
||||||
for (var i = _WidgetsPlugin[type].length - 1; i >= 0; i--) { |
if (_WidgetsPlugin[type]) { |
||||||
if (res = _WidgetsPlugin[type][i](options)) { |
for (let i = _WidgetsPlugin[type].length - 1; i >= 0; i--) { |
||||||
return res; |
res = _WidgetsPlugin[type][i](options); |
||||||
} |
if (res) { |
||||||
|
return res; |
||||||
} |
} |
||||||
} |
} |
||||||
return options; |
} |
||||||
}, |
|
||||||
|
return options; |
||||||
|
}, |
||||||
|
|
||||||
config: function (widgetConfigFn, objectConfigFn) { |
config (widgetConfigFn, objectConfigFn) { |
||||||
_GlobalWidgetConfigFns = _GlobalWidgetConfigFns.concat(BI._.isArray(widgetConfigFn) ? widgetConfigFn : [widgetConfigFn]); |
_GlobalWidgetConfigFns = _GlobalWidgetConfigFns.concat(BI._.isArray(widgetConfigFn) ? widgetConfigFn : [widgetConfigFn]); |
||||||
__GlobalObjectConfigFns = __GlobalObjectConfigFns.concat(BI._.isArray(objectConfigFn) ? objectConfigFn : [objectConfigFn]); |
__GlobalObjectConfigFns = __GlobalObjectConfigFns.concat(BI._.isArray(objectConfigFn) ? objectConfigFn : [objectConfigFn]); |
||||||
}, |
}, |
||||||
|
|
||||||
configWidget: function (type, fn, opt) { |
configWidget (type, fn, opt) { |
||||||
// opt.single: true 最后一次注册有效
|
// opt.single: true 最后一次注册有效
|
||||||
if (!_ConfigPlugin[type] || (opt && opt.single)) { |
if (!_ConfigPlugin[type] || (opt && opt.single)) { |
||||||
_ConfigPlugin[type] = []; |
_ConfigPlugin[type] = []; |
||||||
} |
} |
||||||
_ConfigPlugin[type].push(fn); |
_ConfigPlugin[type].push(fn); |
||||||
}, |
}, |
||||||
|
|
||||||
getRender: function (type, rendered) { |
getRender (type, rendered) { |
||||||
var res; |
let res; |
||||||
if (_ConfigRenderPlugin[type]) { |
if (_ConfigRenderPlugin[type]) { |
||||||
for (var i = _ConfigRenderPlugin[type].length - 1; i >= 0; i--) { |
for (let i = _ConfigRenderPlugin[type].length - 1; i >= 0; i--) { |
||||||
if (res = _ConfigRenderPlugin[type][i](rendered)) { |
res = _ConfigRenderPlugin[type][i](rendered); |
||||||
rendered = res; |
if (res) { |
||||||
} |
rendered = res; |
||||||
} |
} |
||||||
} |
} |
||||||
return rendered; |
} |
||||||
}, |
|
||||||
|
return rendered; |
||||||
|
}, |
||||||
|
|
||||||
configRender: function (type, fn) { |
configRender (type, fn) { |
||||||
if (!_ConfigRenderPlugin[type]) { |
if (!_ConfigRenderPlugin[type]) { |
||||||
_ConfigRenderPlugin[type] = []; |
_ConfigRenderPlugin[type] = []; |
||||||
} |
} |
||||||
_ConfigRenderPlugin[type].push(fn); |
_ConfigRenderPlugin[type].push(fn); |
||||||
}, |
}, |
||||||
|
|
||||||
// Deprecated
|
// Deprecated
|
||||||
registerWidget: function (type, fn) { |
registerWidget (type, fn) { |
||||||
if (!_WidgetsPlugin[type]) { |
if (!_WidgetsPlugin[type]) { |
||||||
_WidgetsPlugin[type] = []; |
_WidgetsPlugin[type] = []; |
||||||
} |
} |
||||||
if (_WidgetsPlugin[type].length > 0) { |
if (_WidgetsPlugin[type].length > 0) { |
||||||
console.log("组件已经注册过了!"); |
console.log("组件已经注册过了!"); |
||||||
} |
} |
||||||
_WidgetsPlugin[type].push(fn); |
_WidgetsPlugin[type].push(fn); |
||||||
}, |
}, |
||||||
|
|
||||||
// Deprecated
|
// Deprecated
|
||||||
relieveWidget: function (type) { |
relieveWidget (type) { |
||||||
delete _WidgetsPlugin[type]; |
delete _WidgetsPlugin[type]; |
||||||
}, |
}, |
||||||
|
|
||||||
getObject: function (type, object) { |
getObject (type, object) { |
||||||
if (__GlobalObjectConfigFns.length > 0) { |
if (__GlobalObjectConfigFns.length > 0) { |
||||||
var fns = __GlobalObjectConfigFns.slice(0); |
const fns = __GlobalObjectConfigFns.slice(0); |
||||||
for (var i = fns.length - 1; i >= 0; i--) { |
for (let i = fns.length - 1; i >= 0; i--) { |
||||||
fns[i](type, object); |
fns[i](type, object); |
||||||
} |
|
||||||
} |
} |
||||||
|
} |
||||||
|
|
||||||
if (_ObjectPlugin[type]) { |
let res; |
||||||
var res; |
if (_ObjectPlugin[type]) { |
||||||
for (var i = 0, len = _ObjectPlugin[type].length; i < len; i++) { |
for (let i = 0, len = _ObjectPlugin[type].length; i < len; i++) { |
||||||
if (res = _ObjectPlugin[type][i](object)) { |
res = _ObjectPlugin[type][i](object); |
||||||
object = res; |
if (res) { |
||||||
} |
object = res; |
||||||
} |
} |
||||||
} |
} |
||||||
return res || object; |
} |
||||||
}, |
|
||||||
|
return res || object; |
||||||
hasObject: function (type) { |
}, |
||||||
return __GlobalObjectConfigFns.length > 0 || !!_ObjectPlugin[type]; |
|
||||||
}, |
|
||||||
|
|
||||||
registerObject: function (type, fn) { |
hasObject (type) { |
||||||
if (!_ObjectPlugin[type]) { |
return __GlobalObjectConfigFns.length > 0 || !!_ObjectPlugin[type]; |
||||||
_ObjectPlugin[type] = []; |
}, |
||||||
} |
|
||||||
if (_ObjectPlugin[type].length > 0) { |
|
||||||
console.log("对象已经注册过了!"); |
|
||||||
} |
|
||||||
_ObjectPlugin[type].push(fn); |
|
||||||
}, |
|
||||||
|
|
||||||
relieveObject: function (type) { |
registerObject (type, fn) { |
||||||
delete _ObjectPlugin[type]; |
if (!_ObjectPlugin[type]) { |
||||||
|
_ObjectPlugin[type] = []; |
||||||
|
} |
||||||
|
if (_ObjectPlugin[type].length > 0) { |
||||||
|
console.log("对象已经注册过了!"); |
||||||
} |
} |
||||||
}); |
_ObjectPlugin[type].push(fn); |
||||||
})(); |
}, |
||||||
|
|
||||||
|
relieveObject (type) { |
||||||
|
delete _ObjectPlugin[type]; |
||||||
|
}, |
||||||
|
}; |
||||||
|
@ -1,9 +1,21 @@ |
|||||||
|
// export * from "../../typescript/core/decorator/decorator.ts";
|
||||||
|
|
||||||
|
import { shortcut as biShortcut, provider as biProvider } from "./5.inject"; |
||||||
|
|
||||||
/** |
/** |
||||||
* 注册widget |
* 注册widget |
||||||
*/ |
*/ |
||||||
import { shortcut as biShortcut } from "./5.inject"; |
|
||||||
export function shortcut() { |
export function shortcut() { |
||||||
return function decorator(Target) { |
return function decorator(Target) { |
||||||
biShortcut(Target.xtype, Target); |
biShortcut(Target.xtype, Target); |
||||||
}; |
}; |
||||||
} |
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 注册provider |
||||||
|
*/ |
||||||
|
export function provider() { |
||||||
|
return function decorator(Target) { |
||||||
|
biProvider(Target.xtype, Target); |
||||||
|
}; |
||||||
|
} |
||||||
|
@ -1,58 +1,59 @@ |
|||||||
BI.Fragment = function () { |
import { isNotNull, isArray, isFunction, isKey, extend } from "./2.base"; |
||||||
}; |
|
||||||
|
|
||||||
BI.h = function (type, props, children) { |
export function Fragment () {} |
||||||
if (children != null) { |
|
||||||
if (!BI.isArray(children)) { |
export function h (type, props, children) { |
||||||
|
if (isNotNull(children)) { |
||||||
|
if (!isArray(children)) { |
||||||
children = [children]; |
children = [children]; |
||||||
} |
} |
||||||
} else { |
} else { |
||||||
children = []; |
children = []; |
||||||
} |
} |
||||||
if (arguments.length > 3) { |
if (arguments.length > 3) { |
||||||
for (var i = 3; i < arguments.length; i++) { |
for (let i = 3; i < arguments.length; i++) { |
||||||
if (BI.isArray(arguments[i])) { |
if (isArray(arguments[i])) { |
||||||
children = children.concat(arguments[i]); |
children = children.concat(arguments[i]); |
||||||
} else { |
} else { |
||||||
children.push(arguments[i]); |
children.push(arguments[i]); |
||||||
} |
} |
||||||
} |
} |
||||||
} |
} |
||||||
if (type === BI.Fragment) { |
if (type === Fragment) { |
||||||
return children; |
return children; |
||||||
} |
} |
||||||
if (BI.isFunction(type)) { |
if (isFunction(type)) { |
||||||
type = type.xtype || type; |
type = type.xtype || type; |
||||||
} |
} |
||||||
if (type === "el") { |
if (type === "el") { |
||||||
return BI.extend({ |
return extend({ |
||||||
el: children[0] |
el: children[0], |
||||||
}, props); |
}, props); |
||||||
} |
} |
||||||
if (type === "left") { |
if (type === "left") { |
||||||
return BI.extend({ |
return extend({ |
||||||
left: children |
left: children, |
||||||
}, props); |
}, props); |
||||||
} |
} |
||||||
if (type === "right") { |
if (type === "right") { |
||||||
return BI.extend({ |
return extend({ |
||||||
right: children |
right: children, |
||||||
}, props); |
}, props); |
||||||
} |
} |
||||||
if (children.length === 1) { |
if (children.length === 1) { |
||||||
if (BI.isKey(children[0])) { |
if (isKey(children[0])) { |
||||||
return BI.extend({ |
return extend({ |
||||||
type: type |
type, |
||||||
}, { text: children[0] }, props); |
}, { text: children[0] }, props); |
||||||
} |
} |
||||||
if (BI.isFunction(children[0])) { |
if (isFunction(children[0])) { |
||||||
return BI.extend({ |
return extend({ |
||||||
type: type |
type, |
||||||
}, { items: children[0] }, props); |
}, { items: children[0] }, props); |
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
return BI.extend({ |
return extend({ |
||||||
type: type |
type, |
||||||
}, children.length > 0 ? { items: children } : {}, props); |
}, children.length > 0 ? { items: children } : {}, props); |
||||||
}; |
} |
||||||
|
@ -1,51 +1,54 @@ |
|||||||
!(function () { |
import { isPlainObject, extend, each, isArray } from "./2.base"; |
||||||
BI.useInWorker = function () { |
import { Models } from "./5.inject"; |
||||||
function createWatcher (model, keyOrFn, cb, options) { |
|
||||||
if (BI.isPlainObject(cb)) { |
export function useInWorker () { |
||||||
options = cb; |
function createWatcher (model, keyOrFn, cb, options) { |
||||||
cb = cb.handler; |
if (isPlainObject(cb)) { |
||||||
} |
options = cb; |
||||||
options = options || {}; |
cb = cb.handler; |
||||||
return Fix.watch(model, keyOrFn, cb, BI.extend(options, { |
|
||||||
store: model |
|
||||||
})); |
|
||||||
} |
} |
||||||
|
options = options || {}; |
||||||
|
|
||||||
|
return Fix.watch(model, keyOrFn, cb, extend(options, { |
||||||
|
store: model, |
||||||
|
})); |
||||||
|
} |
||||||
|
|
||||||
var models = {}, watches = {}; |
const models = {}, watches = {}; |
||||||
addEventListener("message", function (e) { |
addEventListener("message", e => { |
||||||
var data = e.data; |
const data = e.data; |
||||||
switch (data.eventType) { |
let store; |
||||||
case "action": |
switch (data.eventType) { |
||||||
models[data.name][data.action].apply(models[data.name], data.args); |
case "action": |
||||||
break; |
models[data.name][data.action](...data.args); |
||||||
case "destroy": |
break; |
||||||
BI.each(watches[data.name], function (i, unwatches) { |
case "destroy": |
||||||
unwatches = BI.isArray(unwatches) ? unwatches : [unwatches]; |
each(watches[data.name], (i, unwatches) => { |
||||||
BI.each(unwatches, function (j, unwatch) { |
unwatches = isArray(unwatches) ? unwatches : [unwatches]; |
||||||
unwatch(); |
each(unwatches, (j, unwatch) => { |
||||||
}); |
unwatch(); |
||||||
}); |
}); |
||||||
delete models[data.name]; |
}); |
||||||
delete watches[data.name]; |
delete models[data.name]; |
||||||
break; |
delete watches[data.name]; |
||||||
case "create": |
break; |
||||||
var store = models[data.name] = BI.Models.getModel(data.type, data.options); |
case "create": |
||||||
watches[data.name] = []; |
store = models[data.name] = Models.getModel(data.type, data.options); |
||||||
BI.each(data.watches, function (i, key) { |
watches[data.name] = []; |
||||||
watches[data.name].push(createWatcher(store.model, key, function (newValue, oldValue) { |
each(data.watches, (i, key) => { |
||||||
postMessage(BI.extend({}, data, { |
watches[data.name].push(createWatcher(store.model, key, (newValue, oldValue) => { |
||||||
eventType: "watch", |
postMessage(extend({}, data, { |
||||||
currentWatchType: key |
eventType: "watch", |
||||||
}, {args: [newValue, oldValue]})); |
currentWatchType: key, |
||||||
})); |
}, { args: [newValue, oldValue] })); |
||||||
}); |
})); |
||||||
postMessage(BI.extend({}, data, { |
}); |
||||||
eventType: "create" |
postMessage(extend({}, data, { |
||||||
}, {msg: store.model})); |
eventType: "create", |
||||||
break; |
}, { msg: store.model })); |
||||||
default: |
break; |
||||||
break; |
default: |
||||||
} |
break; |
||||||
}, false); |
} |
||||||
}; |
}, false); |
||||||
}()); |
} |
||||||
|
Loading…
Reference in new issue