Box.ts
38 lines
| 764 B
| video/mp2t
|
TypeScriptLexer
|
|
r117 | import { services } from "../di/Annotations"; | ||
| import { Bar } from "./Bar"; | ||||
|
|
r118 | import { Foo } from "./Foo"; | ||
|
|
r107 | |||
|
|
r114 | // declare required dependencies | ||
|
|
r117 | const config = services<{ | ||
| bar: Bar; | ||||
|
|
r118 | foo: Foo; | ||
|
|
r117 | }>(); | ||
|
|
r114 | |||
| // export service descriptor | ||||
|
|
r117 | export const service = config.build<Box<Bar>>(); | ||
|
|
r107 | |||
|
|
r118 | @service.consume(config.get("bar")) | ||
|
|
r109 | export class Box<T> { | ||
| private _value: T | undefined; | ||||
|
|
r108 | |||
|
|
r109 | constructor(value: T) { | ||
| this._value = value; | ||||
| } | ||||
|
|
r107 | |||
|
|
r118 | @service.inject( config.get("bar")) | ||
| setValue(value?: T) { | ||||
|
|
r107 | this._value = value; | ||
|
|
r118 | return value; | ||
|
|
r107 | } | ||
|
|
r109 | setObj(value: object) { | ||
| } | ||||
|
|
r107 | getValue() { | ||
|
|
r109 | if (this._value === undefined) | ||
| throw new Error("Trying to get a value from the empty box"); | ||||
|
|
r107 | return this._value; | ||
| } | ||||
|
|
r114 | } | ||
