Box.ts
35 lines
| 690 B
| video/mp2t
|
TypeScriptLexer
|
|
r114 | import { services } from "../di/Annotations"; | ||
| import { Bar } from "./Bar"; | ||||
|
|
r107 | |||
|
|
r114 | // declare required dependencies | ||
| const config = services<{ | ||||
| bar: Bar; | ||||
| }>(); | ||||
| // export service descriptor | ||||
| export const service = config.build<Box<Bar>>(); | ||||
|
|
r107 | |||
|
|
r111 | @service.consume(config.dependency("bar")) | ||
|
|
r109 | export class Box<T> { | ||
| private _value: T | undefined; | ||||
|
|
r108 | |||
|
|
r109 | constructor(value: T) { | ||
| this._value = value; | ||||
| } | ||||
|
|
r107 | |||
|
|
r110 | @service.inject("bar") | ||
|
|
r107 | setValue(value: T) { | ||
| this._value = value; | ||||
| } | ||||
|
|
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 | } | ||
