add ContextConsumer to get instance of NotificationService

This commit is contained in:
Jacob Overgaard
2022-12-20 14:27:44 +01:00
parent 40837918ec
commit 8732dcf029

View File

@@ -2,24 +2,37 @@
import { ReactiveController, ReactiveControllerHost } from 'lit';
import { ApiError, CancelablePromise, ProblemDetails } from '@umbraco-cms/backend-api';
import { UmbNotificationOptions, UmbNotificationDefaultData, UmbNotificationService } from '@umbraco-cms/services';
import { UmbContextConsumer } from '@umbraco-cms/context-api';
export class UmbResourceController implements ReactiveController {
host: ReactiveControllerHost;
#promises: Promise<any>[] = [];
#notificationConsumer: UmbContextConsumer;
#notificationService?: UmbNotificationService;
constructor(host: ReactiveControllerHost) {
(this.host = host).addController(this);
this.#notificationConsumer = new UmbContextConsumer(
host as unknown as EventTarget,
'umbNotificationService',
(_instance: UmbNotificationService) => {
this.#notificationService = _instance;
}
);
}
hostConnected() {
this.#promises.length = 0;
this.#notificationConsumer.attach();
}
hostDisconnected() {
this.cancelAllResources();
this.#notificationConsumer.detach();
}
addResource(promise: Promise<any>): void {