From 138899686531317658ead0bb064ef1ab4a0ef187 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niels=20Lyngs=C3=B8?= Date: Mon, 9 Jan 2023 20:23:11 +0100 Subject: [PATCH] modal service --- .../src/core/modal/modal.service.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/core/modal/modal.service.ts b/src/Umbraco.Web.UI.Client/src/core/modal/modal.service.ts index 289f52f2a6..3525d0ae0f 100644 --- a/src/Umbraco.Web.UI.Client/src/core/modal/modal.service.ts +++ b/src/Umbraco.Web.UI.Client/src/core/modal/modal.service.ts @@ -5,7 +5,7 @@ import './layouts/property-editor-ui-picker/modal-layout-property-editor-ui-pick import './layouts/modal-layout-current-user.element'; import { UUIModalSidebarSize } from '@umbraco-ui/uui-modal-sidebar'; -import { BehaviorSubject, Observable } from 'rxjs'; +import { UniqueBehaviorSubject } from '../observable-api/unique-behavior-subject'; import { UmbModalChangePasswordData } from './layouts/modal-layout-change-password.element'; import type { UmbModalIconPickerData } from './layouts/icon-picker/modal-layout-icon-picker.element'; @@ -24,9 +24,11 @@ export interface UmbModalOptions { data?: UmbModalData; } +// TODO: Should this be called UmbModalContext ? as we don't have 'services' as a term. export class UmbModalService { - private _modals: BehaviorSubject> = new BehaviorSubject(>[]); - public readonly modals: Observable> = this._modals.asObservable(); + + #modals = new UniqueBehaviorSubject(>[]); + public readonly modals = this.#modals.asObservable(); /** * Opens a Confirm modal @@ -105,7 +107,7 @@ export class UmbModalService { modalHandler.element.addEventListener('close-end', () => this._handleCloseEnd(modalHandler)); - this._modals.next([...this._modals.getValue(), modalHandler]); + this.#modals.next([...this.#modals.getValue(), modalHandler]); return modalHandler; } @@ -116,7 +118,7 @@ export class UmbModalService { * @memberof UmbModalService */ private _close(key: string) { - this._modals.next(this._modals.getValue().filter((modal) => modal.key !== key)); + this.#modals.next(this.#modals.getValue().filter((modal) => modal.key !== key)); } /**