From 0b97e79c478f1650526e5f4bc252a3aaa6ac3917 Mon Sep 17 00:00:00 2001 From: alina sireneva Date: Wed, 1 May 2024 23:02:16 +0300 Subject: [PATCH] feat(dispatcher): allow injecting multiple deps at once --- packages/dispatcher/src/dispatcher.ts | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/packages/dispatcher/src/dispatcher.ts b/packages/dispatcher/src/dispatcher.ts index 8ae5bf77..b896b508 100644 --- a/packages/dispatcher/src/dispatcher.ts +++ b/packages/dispatcher/src/dispatcher.ts @@ -204,12 +204,28 @@ export class Dispatcher { * * **Note**: This is only available for the root dispatcher. */ - inject(name: Name, value: DispatcherDependencies[Name]): void { + inject(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): void + inject( + name: Name | Partial, + 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! + } } /**