| @@ -0,0 +1,11 | |||||
|
|
1 | import { Constructor } from "../interfaces"; | |||
|
|
2 | ||||
|
|
3 | export interface InjectOptions { | |||
|
|
4 | lazy?: boolean; | |||
|
|
5 | } | |||
|
|
6 | ||||
|
|
7 | export function inject<I extends { [name in keyof I]: (v: any) => void } >(dependency: string) { | |||
|
|
8 | return <M extends keyof I>(target: any, memberName: M, descriptor: TypedPropertyDescriptor<I[M]> ) => { | |||
|
|
9 | ||||
|
|
10 | }; | |||
|
|
11 | } | |||
| @@ -0,0 +1,18 | |||||
|
|
1 | import { inject } from "../di/Annotations"; | |||
|
|
2 | ||||
|
|
3 | export interface Injector<T> { | |||
|
|
4 | setValue(value: T); | |||
|
|
5 | } | |||
|
|
6 | ||||
|
|
7 | export class Box<T> implements Injector<T> { | |||
|
|
8 | private _value: T; | |||
|
|
9 | ||||
|
|
10 | @inject<Injector<T>>("bar") | |||
|
|
11 | setValue(value: T) { | |||
|
|
12 | this._value = value; | |||
|
|
13 | } | |||
|
|
14 | ||||
|
|
15 | getValue() { | |||
|
|
16 | return this._value; | |||
|
|
17 | } | |||
|
|
18 | } | |||
| @@ -0,0 +1,36 | |||||
|
|
1 | import { Constructor } from "../interfaces"; | |||
|
|
2 | import { ActivationType } from "../di/interfaces"; | |||
|
|
3 | ||||
|
|
4 | namespace MyLib { | |||
|
|
5 | interface Resolver<S> { | |||
|
|
6 | <K extends keyof S>(name: K): S[K]; | |||
|
|
7 | <K extends keyof S>(lazy: K): (overrides?: {}) => S[K]; | |||
|
|
8 | } | |||
|
|
9 | ||||
|
|
10 | interface RegistrationOptions<S> { | |||
|
|
11 | activation?: ActivationType; | |||
|
|
12 | services?: BuilderContext<S>; | |||
|
|
13 | } | |||
|
|
14 | ||||
|
|
15 | interface BuilderContext<S> { | |||
|
|
16 | registerType<T extends Constructor, K extends string>( | |||
|
|
17 | name: K, | |||
|
|
18 | constructor: T, | |||
|
|
19 | options?: RegistrationOptions<S> | |||
|
|
20 | ): BuilderContext<S & { K: T }>; | |||
|
|
21 | ||||
|
|
22 | registerFactory<T, K extends string>( | |||
|
|
23 | name: K, | |||
|
|
24 | factory: (resolver: Resolver<S>) => T, | |||
|
|
25 | options?: RegistrationOptions<S> | |||
|
|
26 | ): BuilderContext<S & { K: T }>; | |||
|
|
27 | ||||
|
|
28 | registerInstance<T, K extends string>( | |||
|
|
29 | name: K, | |||
|
|
30 | instance: T, | |||
|
|
31 | ownership?: boolean | |||
|
|
32 | ): BuilderContext<S & { K: T }>; | |||
|
|
33 | } | |||
|
|
34 | } | |||
|
|
35 | ||||
|
|
36 | export = MyLib; | |||
| @@ -1,2 +1,13 | |||||
|
|
1 | arguments= | |||
|
|
2 | auto.sync=false | |||
|
|
3 | build.scans.enabled=false | |||
|
|
4 | connection.gradle.distribution=GRADLE_DISTRIBUTION(WRAPPER) | |||
| 1 | connection.project.dir= |
|
5 | connection.project.dir= | |
| 2 | eclipse.preferences.version=1 |
|
6 | eclipse.preferences.version=1 | |
|
|
7 | gradle.user.home= | |||
|
|
8 | java.home=/usr/lib64/jvm/java | |||
|
|
9 | jvm.arguments= | |||
|
|
10 | offline.mode=false | |||
|
|
11 | override.workspace.settings=true | |||
|
|
12 | show.console.view=true | |||
|
|
13 | show.executions.view=true | |||
| @@ -1,5 +1,5 | |||||
| 1 | plugins { |
|
1 | plugins { | |
| 2 |
id "org.implab.gradle-typescript" version "1.3. |
|
2 | id "org.implab.gradle-typescript" version "1.3.3" | |
| 3 | id "org.implab.gradle-hg" |
|
3 | id "org.implab.gradle-hg" | |
| 4 | id "ivy-publish" |
|
4 | id "ivy-publish" | |
| 5 | } |
|
5 | } | |
| @@ -52,7 +52,7 typescript { | |||||
| 52 |
|
52 | |||
| 53 | if(symbols != 'none') { |
|
53 | if(symbols != 'none') { | |
| 54 | sourceMap = true |
|
54 | sourceMap = true | |
| 55 |
sourceRoot = |
|
55 | sourceRoot = packageName | |
| 56 | } |
|
56 | } | |
| 57 |
|
57 | |||
| 58 | if (flavour == 'node') { |
|
58 | if (flavour == 'node') { | |
| @@ -113,15 +113,15 export class Container { | |||||
| 113 | return new Container(this); |
|
113 | return new Container(this); | |
| 114 | } |
|
114 | } | |
| 115 |
|
115 | |||
| 116 | has(id) { |
|
116 | has(id: string | number) { | |
| 117 | return id in this._cache; |
|
117 | return id in this._cache; | |
| 118 | } |
|
118 | } | |
| 119 |
|
119 | |||
| 120 | get(id) { |
|
120 | get(id: string | number) { | |
| 121 | return this._cache[id]; |
|
121 | return this._cache[id]; | |
| 122 | } |
|
122 | } | |
| 123 |
|
123 | |||
| 124 | store(id, value) { |
|
124 | store(id: string | number, value: any) { | |
| 125 | return (this._cache[id] = value); |
|
125 | return (this._cache[id] = value); | |
| 126 | } |
|
126 | } | |
| 127 |
|
127 | |||
| @@ -1,9 +1,11 | |||||
| 1 | { |
|
1 | { | |
| 2 | "compilerOptions": { |
|
2 | "compilerOptions": { | |
| 3 | "moduleResolution": "node", |
|
3 | "moduleResolution": "node", | |
|
|
4 | "experimentalDecorators": true, | |||
| 4 | "noEmitOnError": true, |
|
5 | "noEmitOnError": true, | |
| 5 | "listFiles": true, |
|
6 | "listFiles": true, | |
| 6 | "types": [], |
|
7 | "types": [], | |
|
|
8 | "target": "ES5", | |||
| 7 | "lib": ["es5", "es2015.promise", "es2015.symbol", "es2015.iterable", "dom", "scripthost"] |
|
9 | "lib": ["es5", "es2015.promise", "es2015.symbol", "es2015.iterable", "dom", "scripthost"] | |
| 8 | } |
|
10 | } | |
| 9 | } No newline at end of file |
|
11 | } | |
General Comments 0
You need to be logged in to leave comments.
Login now
