Comparing version 0.3.10 to 0.3.11
@@ -13,8 +13,2 @@ "use strict"; | ||
exports.contextTypeSymbol = Symbol('contextType'); | ||
function registerInstance(ioc, value, clsType, app, ctx) { | ||
ioc.register(value, clsType); | ||
ioc.inject(value, (_globalType, typeCls) => { | ||
return getInstance(typeCls, app, ctx); | ||
}); | ||
} | ||
function getInstance(clsType, app, ctx) { | ||
@@ -29,3 +23,3 @@ let ioc = undefined; | ||
if (!targetClsType) { | ||
throw new Error(`ClassType [${utils_1.getGlobalType(clsType)}] NOT found!`); | ||
throw new Error(`ClassType [${utils_1.getGlobalType(clsType)}] NOT found in typeLoader!`); | ||
} | ||
@@ -43,42 +37,41 @@ const from = targetClsType[exports.contextTypeSymbol]; | ||
let value = ioc.get(clsType); | ||
if (!value) { | ||
if (!targetClsType) { | ||
throw new Error(`classType NOT registered! [${utils_1.getGlobalType(clsType)}]`); | ||
if (value) { | ||
return value; | ||
} | ||
if (from === 'Application') { | ||
if (!app) { | ||
throw new Error(`inject [${utils_1.getGlobalType(clsType)}] MUST in Application/Context class instance.`); | ||
} | ||
if (from === 'Application') { | ||
if (!app) { | ||
throw new Error(`inject [${utils_1.getGlobalType(clsType)}] MUST in Application/Context class instance.`); | ||
} | ||
if (useCtxProxyForAppComponent) { | ||
value = app.iocContext.get(clsType); | ||
} | ||
if (useCtxProxyForAppComponent) { | ||
value = app.iocContext.get(clsType); | ||
if (!value) { | ||
value = ciHooks.reduce((pre, cur) => cur(pre, app), new targetClsType(app)); | ||
value = new targetClsType(app); | ||
appctx_1.setApp(value, app); | ||
if (useCtxProxyForAppComponent) { | ||
registerInstance(app.iocContext, value, clsType, app, ctx); | ||
} | ||
app.iocContext.register(value, clsType); | ||
} | ||
if (useCtxProxyForAppComponent) { | ||
value = new Proxy(value, { | ||
get(target, property) { | ||
if (property === appctx_1.ctxSymbol) { | ||
return ctx; | ||
} | ||
return target[property]; | ||
value = new Proxy(value, { | ||
get(target, property) { | ||
if (property === appctx_1.ctxSymbol) { | ||
return ctx; | ||
} | ||
}); | ||
} | ||
return typeof target[property] === 'function' ? target[property].bind(this) : target[property]; | ||
} | ||
}); | ||
value = ciHooks.reduce((pre, cur) => cur(pre, app), value); | ||
} | ||
else if (from === 'Context') { | ||
if (!ctx) { | ||
throw new Error(`inject [${utils_1.getGlobalType(clsType)}] MUST in Context class instance.`); | ||
} | ||
value = ciHooks.reduce((pre, cur) => cur(pre, app, ctx), new targetClsType(ctx)); | ||
appctx_1.setCtx(value, ctx); | ||
else { | ||
value = ciHooks.reduce((pre, cur) => cur(pre, app), new targetClsType(app)); | ||
appctx_1.setApp(value, app); | ||
} | ||
registerInstance(ioc, value, clsType, app, ctx); | ||
} | ||
else if (from === 'Context') { | ||
if (!ctx) { | ||
throw new Error(`inject [${utils_1.getGlobalType(clsType)}] MUST in Context class instance.`); | ||
} | ||
value = ciHooks.reduce((pre, cur) => cur(pre, app, ctx), new targetClsType(ctx)); | ||
appctx_1.setCtx(value, ctx); | ||
} | ||
ioc.register(value, clsType); | ||
return value; | ||
} | ||
exports.getInstance = getInstance; |
{ | ||
"name": "egg-aop", | ||
"version": "0.3.10", | ||
"version": "0.3.11", | ||
"description": "aop for egg.", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
16496
414