feat(dispatcher): allow injecting multiple deps at once
This commit is contained in:
parent
f277bbc41c
commit
0b97e79c47
1 changed files with 18 additions and 2 deletions
|
@ -204,12 +204,28 @@ export class Dispatcher<State extends object = never> {
|
|||
*
|
||||
* **Note**: This is only available for the root dispatcher.
|
||||
*/
|
||||
inject<Name extends keyof DispatcherDependencies>(name: Name, value: DispatcherDependencies[Name]): void {
|
||||
inject<Name extends keyof DispatcherDependencies>(name: Name, value: DispatcherDependencies[Name]): void
|
||||
/**
|
||||
* Inject dependencies to be available in this dispatcher and all its children.
|
||||
*
|
||||
* **Note**: This is only available for the root dispatcher.
|
||||
*/
|
||||
inject(deps: Partial<DispatcherDependencies>): void
|
||||
inject<Name extends keyof DispatcherDependencies>(
|
||||
name: Name | Partial<DispatcherDependencies>,
|
||||
value?: DispatcherDependencies[Name],
|
||||
): void {
|
||||
if (this._parent) {
|
||||
throw new MtArgumentError('Cannot inject dependencies to child dispatchers')
|
||||
}
|
||||
|
||||
this._deps[name] = value
|
||||
if (typeof name === 'object') {
|
||||
for (const [k, v] of Object.entries(name)) {
|
||||
(this._deps as any)[k] = v
|
||||
}
|
||||
} else {
|
||||
this._deps[name] = value!
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue