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