typeioc-examples
Advanced tools
Comparing version 0.0.1 to 1.0.0
{ | ||
"name": "typeioc-examples", | ||
"version": "0.0.1", | ||
"version": "1.0.0", | ||
"description": "TypeIOC getting started examples", | ||
"scripts": {}, | ||
"scripts": { | ||
"test": "tap src/**/*.test.js src/**/*.test.ts" | ||
}, | ||
"author": { | ||
@@ -12,4 +14,8 @@ "name": "Max Gherman", | ||
"dependencies": { | ||
"typeioc": "^2.1.8" | ||
"typeioc": "2.1.8" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "12.0.8", | ||
"tap": "14.2.3" | ||
} | ||
} |
@@ -42,2 +42,4 @@ const typeioc = require('typeioc'); | ||
console.log(`${a1.name}\n${b1.name}\n${c1.name}\n${a2.name}\n${b2.name}\n${c2.name}`); | ||
const result = `${a1.name} ${b1.name} ${c1.name} ${a2.name} ${b2.name} ${c2.name}`; | ||
module.exports = result |
@@ -43,2 +43,4 @@ import * as typeioc from 'typeioc'; | ||
console.log(`${a1.name}\n${b1.name}\n${c1.name}\n${a2.name}\n${b2.name}\n${c2.name}`); | ||
const result = `${a1.name} ${b1.name} ${c1.name} ${a2.name} ${b2.name} ${c2.name}` | ||
export default result |
@@ -27,6 +27,10 @@ const typeioc = require('typeioc'); | ||
try { | ||
container.resolve(A); | ||
} catch (error) { | ||
console.log(error.message); | ||
} | ||
const result = () => { | ||
try { | ||
container.resolve(A); | ||
} catch (error) { | ||
return error.message | ||
} | ||
} | ||
module.exports = result() |
@@ -27,6 +27,10 @@ import * as typeioc from 'typeioc'; | ||
try { | ||
container.resolve(A); | ||
} catch (error) { | ||
console.log(error.message); | ||
} | ||
const result = () => { | ||
try { | ||
container.resolve(A); | ||
} catch (error) { | ||
return error.message; | ||
} | ||
} | ||
export default result() |
@@ -24,3 +24,3 @@ import * as typeioc from 'typeioc'; | ||
interface IDepedency { | ||
interface IDependency { | ||
name: string; | ||
@@ -35,7 +35,7 @@ } | ||
@decorator.by('A').resolve() | ||
private a: IDepedency, | ||
private a: IDependency, | ||
@decorator.by('B').name('B1').resolve() | ||
private b: IDepedency, | ||
private b: IDependency, | ||
@decorator.resolveValue(new C()) | ||
private c: IDepedency) { | ||
private c: IDependency) { | ||
@@ -50,4 +50,4 @@ } | ||
const container = decorator.build(); | ||
const d = container.resolve<D>('D'); | ||
const result = container.resolve<D>('D'); | ||
console.log(d.name); | ||
export default result.name |
@@ -17,3 +17,3 @@ import * as typeioc from 'typeioc'; | ||
private _name = 'Test'; | ||
constructor() { | ||
@@ -39,2 +39,2 @@ super(); | ||
console.log(actual.name); | ||
export default actual.name |
@@ -44,2 +44,4 @@ const typeioc = require('typeioc'); | ||
console.log(`${b1.name}\n${b2.name}\n${b3.name}`); | ||
const result = `${b1.name} ${b2.name} ${b3.name}` | ||
module.exports = result |
@@ -44,2 +44,4 @@ import * as typeioc from 'typeioc'; | ||
console.log(`${b1.name}\n${b2.name}\n${b3.name}`); | ||
const result = `${b1.name} ${b2.name} ${b3.name}` | ||
export default result |
@@ -52,6 +52,8 @@ const typeioc = require('typeioc'); | ||
const container = builder.build(); | ||
const container = builder.build(); | ||
const b = container.resolve('B Class'); | ||
const c = container.resolve(CClassBase, 1, 2, 3); | ||
console.log(`${b.name} ${c.name}`); | ||
const result = `${b.name} ${c.name}` | ||
module.exports = result |
@@ -51,6 +51,8 @@ import * as typeioc from 'typeioc'; | ||
const container = builder.build(); | ||
const container = builder.build(); | ||
const b = container.resolve<BClass>('B Class'); | ||
const c = container.resolve<CClassBase>(CClassBase, 1, 2, 3); | ||
console.log(`${b.name} ${c.name}`); | ||
const result = `${b.name} ${c.name}` | ||
export default result |
@@ -32,2 +32,3 @@ const typeioc = require('typeioc'); | ||
const instance = container.resolve(SimpleClass); | ||
console.log(instance.name); | ||
module.exports = instance.name |
@@ -31,2 +31,2 @@ import * as typeioc from 'typeioc' | ||
console.log(instance.name); | ||
export default instance.name |
@@ -24,2 +24,3 @@ const typeioc = require('typeioc'); | ||
const builder = typeioc.createBuilder(); | ||
builder.register('create') | ||
@@ -32,2 +33,3 @@ .as(() => create()) | ||
.instancePerContainer(); | ||
builder.register(A) | ||
@@ -51,4 +53,4 @@ .asSelf() | ||
.map((key) => `${key}: ${state.data[key]} - instances`) | ||
.join('\n'); | ||
.join('; '); | ||
console.log(message); | ||
module.exports = message |
@@ -49,4 +49,4 @@ import * as typeioc from 'typeioc'; | ||
.map((key) => `${key}: ${state.data[key]} - instances`) | ||
.join('\n'); | ||
.join('; '); | ||
console.log(message); | ||
export default message |
@@ -7,3 +7,3 @@ const Addons = require('typeioc/addons'); | ||
const math = interceptor.intercept(Math, [{ | ||
wrapper : (callInfo) => callInfo.next(`${callInfo.result} 2`) | ||
wrapper: (callInfo) => callInfo.next(`${callInfo.result} 2`) | ||
}, { | ||
@@ -24,4 +24,4 @@ method: 'pow', | ||
const result = `math.pow(2, 3) is "${math.pow(2, 3)}"; math.round(5.777) is "${math.round(5.777)}"` | ||
console.log(math.pow(2, 3)); | ||
console.log(math.round(5.777)); | ||
module.exports = result |
@@ -23,4 +23,4 @@ import * as Addons from 'typeioc/addons'; | ||
const result = `math.pow(2, 3) is "${math.pow(2, 3)}"; math.round(5.777) is "${math.round(5.777)}"` | ||
console.log(math.pow(2, 3)); | ||
console.log(math.round(5.777)); | ||
export default result |
@@ -32,6 +32,6 @@ const typeioc = require('typeioc'); | ||
method: 'a', | ||
// intercept 'a' getter | ||
type: Interceptors.CallInfoType.Getter, | ||
// invoke getter in the context of original object | ||
@@ -41,6 +41,6 @@ wrapper: (callInfo) => callInfo.get() + callInfo.source.b | ||
method: 'add', | ||
// invoke original method | ||
wrapper: (callInfo) => callInfo.invoke() | ||
}]); | ||
}]); | ||
@@ -67,2 +67,4 @@ const builder = typeioc.createBuilder(); | ||
console.log(`Original: ${calcAddOriginal.add()}\nIntercepted: ${calcAdd.add()}`); | ||
const result = `Original: ${calcAddOriginal.add()}; Intercepted: ${calcAdd.add()}`; | ||
module.exports = result |
@@ -35,13 +35,13 @@ import * as typeioc from 'typeioc'; | ||
method: 'a', | ||
// intercept 'a' getter | ||
type: Interceptors.CallInfoType.Getter, | ||
wrapper: (callInfo) => callInfo.get() + (callInfo.source as CalcAdd).b | ||
}, { | ||
method: 'add', | ||
// invoke original method | ||
wrapper: (callInfo) => callInfo.invoke() | ||
}]); | ||
}]); | ||
@@ -68,2 +68,4 @@ const builder = typeioc.createBuilder(); | ||
console.log(`Original: ${calcAddOriginal.add()}\nIntercepted: ${calcAdd.add()}`); | ||
const result = `Original: ${calcAddOriginal.add()}; Intercepted: ${calcAdd.add()}`; | ||
export default result |
@@ -8,3 +8,3 @@ const typeioc = require('typeioc'); | ||
const a = c.resolve('F', n, h + n); | ||
return { | ||
@@ -19,6 +19,6 @@ value: h, | ||
const continer = builder.build(); | ||
const lazy = continer.resolve('F', 0, 1)(); | ||
const container = builder.build(); | ||
const lazy = container.resolve('F', 0, 1)(); | ||
const data = [...Array(10).keys()].reduce((acc, curnet) => { | ||
const data = [...Array(10).keys()].reduce((acc) => { | ||
acc.result.push(acc.lazy.value); | ||
@@ -29,2 +29,2 @@ acc.lazy = acc.lazy.next; | ||
console.log(data.result); | ||
module.exports = data.result.join(', ') |
@@ -14,3 +14,3 @@ import * as typeioc from 'typeioc'; | ||
const a = c.resolve<() => IFib>('F', n, h + n); | ||
return { | ||
@@ -34,3 +34,3 @@ value: h, | ||
public next(h, n) { | ||
const value = h; | ||
@@ -48,12 +48,6 @@ const that = this; | ||
let container = builder.build(); | ||
resolveFactoryFunction(container); | ||
container = decorator.build(); | ||
resolveDecorator(container); | ||
function resolveFactoryFunction(container: Typeioc.IContainer) { | ||
const lazy = container.resolve<() => IFib>('F', 0, 1)(); | ||
const data = [...Array(10).keys()].reduce((acc, curnet) => { | ||
const data = [...Array(10).keys()].reduce((acc) => { | ||
acc.result.push(acc.lazy.value); | ||
@@ -63,4 +57,4 @@ acc.lazy = acc.lazy.next; | ||
}, { lazy, result: [] }); | ||
console.log(data.result); | ||
return data.result; | ||
} | ||
@@ -72,3 +66,3 @@ | ||
const data = [...Array(10).keys()].reduce((acc, curnet) => { | ||
const data = [...Array(10).keys()].reduce((acc) => { | ||
acc.result.push(acc.lazy.value); | ||
@@ -79,3 +73,14 @@ acc.lazy = acc.lazy.next; | ||
console.log(data.result); | ||
} | ||
return data.result; | ||
} | ||
const container1 = builder.build(); | ||
const factoryResult = resolveFactoryFunction(container1).join(', '); | ||
const container2 = decorator.build(); | ||
const decoratorResult = resolveDecorator(container2).join(', '); | ||
export { | ||
factoryResult, | ||
decoratorResult | ||
} |
@@ -7,3 +7,3 @@ const typeioc = require('typeioc'); | ||
init() { | ||
state+= ' initialized'; | ||
state+= 'initialized'; | ||
}, | ||
@@ -19,5 +19,5 @@ | ||
.as(() => create()) | ||
.initializeBy((c, item) => { | ||
item.init(); | ||
return item; | ||
.initializeBy((_c, item) => { | ||
item.init(); | ||
return item; | ||
}) | ||
@@ -30,5 +30,5 @@ .dispose((item) => item.cleanup()) | ||
const container = builder.build(); | ||
const service = container.resolveNamed('ServiceA', 'A'); | ||
container.resolveNamed('ServiceA', 'A'); | ||
container.dispose(); | ||
console.log(state); | ||
module.exports = state; |
@@ -12,3 +12,3 @@ import * as typeioc from 'typeioc'; | ||
init() { | ||
state+= ' initialized'; | ||
state+= 'initialized'; | ||
}, | ||
@@ -24,5 +24,5 @@ | ||
.as(() => create()) | ||
.initializeBy((c, item) => { | ||
.initializeBy((_c, item) => { | ||
item.init(); | ||
return item; | ||
return item; | ||
}) | ||
@@ -35,5 +35,5 @@ .dispose((item) => item.cleanup()) | ||
const container = builder.build(); | ||
const service = container.resolveNamed<ICreate>('ServiceA', 'A'); | ||
container.resolveNamed<ICreate>('ServiceA', 'A'); | ||
container.dispose(); | ||
console.log(state); | ||
export default state; |
@@ -25,4 +25,5 @@ const typeioc = require('typeioc'); | ||
const container = builder.build(); | ||
const b = container.resolve(B); | ||
console.log(b.name); | ||
const container = builder.build(); | ||
const result = container.resolve(B); | ||
module.exports = result.name; |
@@ -23,4 +23,5 @@ import * as typeioc from 'typeioc'; | ||
const container = builder.build(); | ||
const b = container.resolve<B>(B); | ||
console.log(b.name); | ||
const container = builder.build(); | ||
const result = container.resolve<B>(B); | ||
export default result.name; |
@@ -46,4 +46,4 @@ const typeioc = require('typeioc'); | ||
.map((key) => `${key}: ${state.data[key]} - instances`) | ||
.join('\n'); | ||
.join('; '); | ||
console.log(message); | ||
module.exports = message |
@@ -46,4 +46,4 @@ import * as typeioc from 'typeioc'; | ||
.map((key) => `${key}: ${state.data[key]} - instances`) | ||
.join('\n'); | ||
.join('; '); | ||
console.log(message); | ||
export default message |
@@ -45,2 +45,2 @@ const typeioc = require('typeioc'); | ||
console.log(message); | ||
module.exports = message |
@@ -45,2 +45,2 @@ import * as typeioc from 'typeioc'; | ||
console.log(message); | ||
export default message; |
@@ -36,5 +36,5 @@ const typeioc = require('typeioc'); | ||
const container = builder.build(); | ||
const c = container.resolve(C); | ||
const container = builder.build(); | ||
const result = container.resolve(C); | ||
console.log(`${c.name()}`); | ||
module.exports = result.name() |
@@ -38,4 +38,5 @@ import * as typeioc from 'typeioc'; | ||
const container = builder.build(); | ||
const container = builder.build(); | ||
const c = container.resolve<{name:() => string}>(C); | ||
console.log(c.name()); | ||
export default c.name(); |
@@ -21,2 +21,3 @@ const typeioc = require('typeioc'); | ||
const service = container.resolve('service'); | ||
console.log(service); | ||
module.exports = service; |
@@ -21,2 +21,3 @@ import * as typeioc from 'typeioc'; | ||
const service = container.resolve('service'); | ||
console.log(service); | ||
export default service; |
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
26513
1030
1
2
Updatedtypeioc@2.1.8