add ContextConsumer to get instance of NotificationService
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user