|
|
|
@ -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 { Widget } from "./4.widget"; |
|
|
|
|
import { Plugin } from "./6.plugin"; |
|
|
|
@ -6,6 +18,7 @@ import { aspect } from "./structure";
|
|
|
|
|
import { Events } from "./constant"; |
|
|
|
|
import { _global } from "./0.foundation"; |
|
|
|
|
import { SystemProvider } from "./system"; |
|
|
|
|
import { loadResources } from "./platform"; |
|
|
|
|
|
|
|
|
|
const moduleInjection = {}, moduleInjectionMap = { |
|
|
|
|
components: {}, |
|
|
|
@ -46,6 +59,7 @@ export function module(xtype, cls) {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const constantInjection = {}; |
|
|
|
|
|
|
|
|
|
export function constant(xtype, cls) { |
|
|
|
|
if (isNotNull(constantInjection[xtype])) { |
|
|
|
|
_global.console && console.error(`constant: [${xtype}]already registered`); |
|
|
|
@ -57,6 +71,7 @@ export function constant(xtype, cls) {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const modelInjection = {}; |
|
|
|
|
|
|
|
|
|
export function model(xtype, cls) { |
|
|
|
|
if (isNotNull(modelInjection[xtype])) { |
|
|
|
|
_global.console && console.error(`model: [${xtype}] already registered`); |
|
|
|
@ -68,6 +83,7 @@ export function model(xtype, cls) {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const storeInjection = {}; |
|
|
|
|
|
|
|
|
|
export function store(xtype, cls) { |
|
|
|
|
if (isNotNull(storeInjection[xtype])) { |
|
|
|
|
_global.console && console.error(`store: [${xtype}] already registered`); |
|
|
|
@ -79,6 +95,7 @@ export function store(xtype, cls) {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const serviceInjection = {}; |
|
|
|
|
|
|
|
|
|
export function service(xtype, cls) { |
|
|
|
|
if ((serviceInjection[xtype])) { |
|
|
|
|
_global.console && console.error(`service: [${xtype}] already registered`); |
|
|
|
@ -90,6 +107,7 @@ export function service(xtype, cls) {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const providerInjection = {}; |
|
|
|
|
|
|
|
|
|
export function provider(xtype, cls) { |
|
|
|
|
if ((providerInjection[xtype])) { |
|
|
|
|
_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) { |
|
|
|
|
if (isFunction(type)) { |
|
|
|
|
opt = configFn; |
|
|
|
@ -196,6 +258,10 @@ export function config(type, configFn, opt) {
|
|
|
|
|
opt, |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
if (opt.deps) { |
|
|
|
|
configWidgetDeps(opt.deps); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (opt.immediately) { |
|
|
|
|
return runConfigFunction(type, configFn); |
|
|
|
|
} |
|
|
|
@ -207,6 +273,7 @@ export function getReference(type, fn) {
|
|
|
|
|
|
|
|
|
|
const actions = {}; |
|
|
|
|
const globalAction = []; |
|
|
|
|
|
|
|
|
|
export function action(type, actionFn) { |
|
|
|
|
if (isFunction(type)) { |
|
|
|
|
globalAction.push(type); |
|
|
|
@ -229,6 +296,7 @@ export function action(type, actionFn) {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const points = {}; |
|
|
|
|
|
|
|
|
|
export function point(type, action, pointFn, after) { |
|
|
|
|
if (!points[type]) { |
|
|
|
|
points[type] = {}; |
|
|
|
@ -243,20 +311,20 @@ export function point(type, action, pointFn, after) {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export const Modules = { |
|
|
|
|
getModule (type) { |
|
|
|
|
getModule(type) { |
|
|
|
|
if (!moduleInjection[type]) { |
|
|
|
|
_global.console && console.error(`module: [${type}] undefined`); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return moduleInjection[type]; |
|
|
|
|
}, |
|
|
|
|
getAllModules () { |
|
|
|
|
getAllModules() { |
|
|
|
|
return moduleInjection; |
|
|
|
|
}, |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
export const Constants = { |
|
|
|
|
getConstant (type) { |
|
|
|
|
getConstant(type) { |
|
|
|
|
if (isNull(constantInjection[type])) { |
|
|
|
|
_global.console && console.error(`constant: [${type}] undefined`); |
|
|
|
|
} |
|
|
|
@ -273,8 +341,8 @@ function callPoint(inst, types) {
|
|
|
|
|
for (const action in points[type]) { |
|
|
|
|
const bfns = points[type][action].before; |
|
|
|
|
if (bfns) { |
|
|
|
|
aspect.before(inst, action, (function (bfns) { |
|
|
|
|
return function () { |
|
|
|
|
aspect.before(inst, action, (function(bfns) { |
|
|
|
|
return function() { |
|
|
|
|
for (let i = 0, len = bfns.length; i < len; i++) { |
|
|
|
|
try { |
|
|
|
|
bfns[i].apply(inst, arguments); |
|
|
|
@ -287,8 +355,8 @@ function callPoint(inst, types) {
|
|
|
|
|
} |
|
|
|
|
const afns = points[type][action].after; |
|
|
|
|
if (afns) { |
|
|
|
|
aspect.after(inst, action, (function (afns) { |
|
|
|
|
return function () { |
|
|
|
|
aspect.after(inst, action, (function(afns) { |
|
|
|
|
return function() { |
|
|
|
|
for (let i = 0, len = afns.length; i < len; i++) { |
|
|
|
|
try { |
|
|
|
|
afns[i].apply(inst, arguments); |
|
|
|
@ -305,7 +373,7 @@ function callPoint(inst, types) {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export const Models = { |
|
|
|
|
getModel (type, config) { |
|
|
|
|
getModel(type, config) { |
|
|
|
|
if (!modelInjection[type]) { |
|
|
|
|
_global.console && console.error(`model: [${type}] undefined`); |
|
|
|
|
} |
|
|
|
@ -321,7 +389,7 @@ export const Models = {
|
|
|
|
|
|
|
|
|
|
const stores = {}; |
|
|
|
|
export const Stores = { |
|
|
|
|
getStore (type, config) { |
|
|
|
|
getStore(type, config) { |
|
|
|
|
if (!storeInjection[type]) { |
|
|
|
|
_global.console && console.error(`store: [${type}] undefined`); |
|
|
|
|
} |
|
|
|
@ -374,7 +442,7 @@ export const Providers = {
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
export const Actions = { |
|
|
|
|
runAction (type, event, config) { |
|
|
|
|
runAction(type, event, config) { |
|
|
|
|
each(actions[type], (i, act) => { |
|
|
|
|
try { |
|
|
|
|
act(event, config); |
|
|
|
@ -383,7 +451,7 @@ export const Actions = {
|
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
}, |
|
|
|
|
runGlobalAction () { |
|
|
|
|
runGlobalAction() { |
|
|
|
|
const args = [].slice.call(arguments); |
|
|
|
|
each(globalAction, (i, act) => { |
|
|
|
|
try { |
|
|
|
@ -396,6 +464,7 @@ export const Actions = {
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const kv = {}; |
|
|
|
|
|
|
|
|
|
export function shortcut(xtype, cls) { |
|
|
|
|
if (isNotNull(kv[xtype])) { |
|
|
|
|
_global.console && console.error(`widget: [${xtype}] already registered`); |
|
|
|
@ -480,7 +549,7 @@ export function createWidget(item, options, context, lazy) {
|
|
|
|
|
if (!w.listeners || isArray(w.listeners)) { |
|
|
|
|
w.listeners = (w.listeners || []).concat([{ |
|
|
|
|
eventName: Events.MOUNT, |
|
|
|
|
action: function () { |
|
|
|
|
action: function() { |
|
|
|
|
Plugin.getObject(elType, this); |
|
|
|
|
}, |
|
|
|
|
}]); |
|
|
|
@ -504,7 +573,7 @@ export function createWidget(item, options, context, lazy) {
|
|
|
|
|
throw new Error("widget: Unable to create widget from item ", item); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export function _lazyCreateWidget (item, options, context) { |
|
|
|
|
export function _lazyCreateWidget(item, options, context) { |
|
|
|
|
return createWidget(item, options, context, true); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|