|
|
@ -1,4 +1,16 @@ |
|
|
|
import { isFunction, isNull, isNotNull, isArray, each, isWidget, extend, init, isEmpty, remove } from "./2.base"; |
|
|
|
import { |
|
|
|
|
|
|
|
isFunction, |
|
|
|
|
|
|
|
isNull, |
|
|
|
|
|
|
|
isNotNull, |
|
|
|
|
|
|
|
isArray, |
|
|
|
|
|
|
|
each, |
|
|
|
|
|
|
|
isWidget, |
|
|
|
|
|
|
|
extend, |
|
|
|
|
|
|
|
init, |
|
|
|
|
|
|
|
isEmpty, |
|
|
|
|
|
|
|
remove, |
|
|
|
|
|
|
|
isString |
|
|
|
|
|
|
|
} from "./2.base"; |
|
|
|
import { OB } from "./3.ob"; |
|
|
|
import { OB } from "./3.ob"; |
|
|
|
import { Widget } from "./4.widget"; |
|
|
|
import { Widget } from "./4.widget"; |
|
|
|
import { Plugin } from "./6.plugin"; |
|
|
|
import { Plugin } from "./6.plugin"; |
|
|
@ -6,6 +18,7 @@ import { aspect } from "./structure"; |
|
|
|
import { Events } from "./constant"; |
|
|
|
import { Events } from "./constant"; |
|
|
|
import { _global } from "./0.foundation"; |
|
|
|
import { _global } from "./0.foundation"; |
|
|
|
import { SystemProvider } from "./system"; |
|
|
|
import { SystemProvider } from "./system"; |
|
|
|
|
|
|
|
import { loadResources } from "./platform"; |
|
|
|
|
|
|
|
|
|
|
|
const moduleInjection = {}, moduleInjectionMap = { |
|
|
|
const moduleInjection = {}, moduleInjectionMap = { |
|
|
|
components: {}, |
|
|
|
components: {}, |
|
|
@ -46,6 +59,7 @@ export function module(xtype, cls) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const constantInjection = {}; |
|
|
|
const constantInjection = {}; |
|
|
|
|
|
|
|
|
|
|
|
export function constant(xtype, cls) { |
|
|
|
export function constant(xtype, cls) { |
|
|
|
if (isNotNull(constantInjection[xtype])) { |
|
|
|
if (isNotNull(constantInjection[xtype])) { |
|
|
|
_global.console && console.error(`constant: [${xtype}]already registered`); |
|
|
|
_global.console && console.error(`constant: [${xtype}]already registered`); |
|
|
@ -57,6 +71,7 @@ export function constant(xtype, cls) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const modelInjection = {}; |
|
|
|
const modelInjection = {}; |
|
|
|
|
|
|
|
|
|
|
|
export function model(xtype, cls) { |
|
|
|
export function model(xtype, cls) { |
|
|
|
if (isNotNull(modelInjection[xtype])) { |
|
|
|
if (isNotNull(modelInjection[xtype])) { |
|
|
|
_global.console && console.error(`model: [${xtype}] already registered`); |
|
|
|
_global.console && console.error(`model: [${xtype}] already registered`); |
|
|
@ -68,6 +83,7 @@ export function model(xtype, cls) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const storeInjection = {}; |
|
|
|
const storeInjection = {}; |
|
|
|
|
|
|
|
|
|
|
|
export function store(xtype, cls) { |
|
|
|
export function store(xtype, cls) { |
|
|
|
if (isNotNull(storeInjection[xtype])) { |
|
|
|
if (isNotNull(storeInjection[xtype])) { |
|
|
|
_global.console && console.error(`store: [${xtype}] already registered`); |
|
|
|
_global.console && console.error(`store: [${xtype}] already registered`); |
|
|
@ -79,6 +95,7 @@ export function store(xtype, cls) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const serviceInjection = {}; |
|
|
|
const serviceInjection = {}; |
|
|
|
|
|
|
|
|
|
|
|
export function service(xtype, cls) { |
|
|
|
export function service(xtype, cls) { |
|
|
|
if ((serviceInjection[xtype])) { |
|
|
|
if ((serviceInjection[xtype])) { |
|
|
|
_global.console && console.error(`service: [${xtype}] already registered`); |
|
|
|
_global.console && console.error(`service: [${xtype}] already registered`); |
|
|
@ -90,6 +107,7 @@ export function service(xtype, cls) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const providerInjection = {}; |
|
|
|
const providerInjection = {}; |
|
|
|
|
|
|
|
|
|
|
|
export function provider(xtype, cls) { |
|
|
|
export function provider(xtype, cls) { |
|
|
|
if ((providerInjection[xtype])) { |
|
|
|
if ((providerInjection[xtype])) { |
|
|
|
_global.console && console.error(`provider: [${xtype}] already registered`); |
|
|
|
_global.console && console.error(`provider: [${xtype}] already registered`); |
|
|
@ -167,6 +185,50 @@ const runConfigFunction = (type, configFn) => { |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 配置组件依赖 |
|
|
|
|
|
|
|
* @param deps |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
function configWidgetDeps(deps) { |
|
|
|
|
|
|
|
each(deps, (key, dep) => { |
|
|
|
|
|
|
|
const deps = (isArray(dep) ? dep : [dep]).map(d => { |
|
|
|
|
|
|
|
if (isString(d)) { |
|
|
|
|
|
|
|
return { |
|
|
|
|
|
|
|
src: d, |
|
|
|
|
|
|
|
async: false |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
return d; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
config(key, props => { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const asyncLoad = deps.some(dep => dep.async); |
|
|
|
|
|
|
|
// 异步加载资源
|
|
|
|
|
|
|
|
if (asyncLoad && !props._depsLoaded) { |
|
|
|
|
|
|
|
return { |
|
|
|
|
|
|
|
type: Widget, |
|
|
|
|
|
|
|
beforeInit: () => { |
|
|
|
|
|
|
|
return loadResources(deps); |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
render: () => { |
|
|
|
|
|
|
|
return { |
|
|
|
|
|
|
|
...props, |
|
|
|
|
|
|
|
_depsLoaded: true |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 同步加载资源
|
|
|
|
|
|
|
|
loadResources(deps); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return props; |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export function config(type, configFn, opt) { |
|
|
|
export function config(type, configFn, opt) { |
|
|
|
if (isFunction(type)) { |
|
|
|
if (isFunction(type)) { |
|
|
|
opt = configFn; |
|
|
|
opt = configFn; |
|
|
@ -196,6 +258,10 @@ export function config(type, configFn, opt) { |
|
|
|
opt, |
|
|
|
opt, |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (opt.deps) { |
|
|
|
|
|
|
|
configWidgetDeps(opt.deps); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (opt.immediately) { |
|
|
|
if (opt.immediately) { |
|
|
|
return runConfigFunction(type, configFn); |
|
|
|
return runConfigFunction(type, configFn); |
|
|
|
} |
|
|
|
} |
|
|
@ -207,6 +273,7 @@ export function getReference(type, fn) { |
|
|
|
|
|
|
|
|
|
|
|
const actions = {}; |
|
|
|
const actions = {}; |
|
|
|
const globalAction = []; |
|
|
|
const globalAction = []; |
|
|
|
|
|
|
|
|
|
|
|
export function action(type, actionFn) { |
|
|
|
export function action(type, actionFn) { |
|
|
|
if (isFunction(type)) { |
|
|
|
if (isFunction(type)) { |
|
|
|
globalAction.push(type); |
|
|
|
globalAction.push(type); |
|
|
@ -229,6 +296,7 @@ export function action(type, actionFn) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const points = {}; |
|
|
|
const points = {}; |
|
|
|
|
|
|
|
|
|
|
|
export function point(type, action, pointFn, after) { |
|
|
|
export function point(type, action, pointFn, after) { |
|
|
|
if (!points[type]) { |
|
|
|
if (!points[type]) { |
|
|
|
points[type] = {}; |
|
|
|
points[type] = {}; |
|
|
@ -396,6 +464,7 @@ export const Actions = { |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
const kv = {}; |
|
|
|
const kv = {}; |
|
|
|
|
|
|
|
|
|
|
|
export function shortcut(xtype, cls) { |
|
|
|
export function shortcut(xtype, cls) { |
|
|
|
if (isNotNull(kv[xtype])) { |
|
|
|
if (isNotNull(kv[xtype])) { |
|
|
|
_global.console && console.error(`widget: [${xtype}] already registered`); |
|
|
|
_global.console && console.error(`widget: [${xtype}] already registered`); |
|
|
|