diff --git a/src/Umbraco.Web.UI.Client/src/backoffice/users/current-user/current-user-history.store.ts b/src/Umbraco.Web.UI.Client/src/backoffice/users/current-user/current-user-history.store.ts index dff63e05d4..892b2a3839 100644 --- a/src/Umbraco.Web.UI.Client/src/backoffice/users/current-user/current-user-history.store.ts +++ b/src/Umbraco.Web.UI.Client/src/backoffice/users/current-user/current-user-history.store.ts @@ -1,4 +1,4 @@ -import { BehaviorSubject, map, Observable } from 'rxjs'; +import { CreateObservablePart, UniqueBehaviorSubject } from 'src/core/observable-api/unique-behavior-subject'; export type UmbModelType = 'dialog' | 'sidebar'; @@ -9,10 +9,13 @@ export type UmbCurrentUserHistoryItem = { }; export class UmbCurrentUserHistoryStore { - private _history: BehaviorSubject> = new BehaviorSubject( + #history = new UniqueBehaviorSubject( >[] ); - public readonly history: Observable> = this._history.asObservable(); + + public readonly history = this.#history.asObservable(); + public readonly latestHistory = CreateObservablePart(this.#history, historyItems => historyItems.slice(-10)); + constructor() { if (!('navigation' in window)) return; @@ -23,14 +26,6 @@ export class UmbCurrentUserHistoryStore { }); } - public getLatestHistory(): Observable> { - return this._history.pipe( - map((historyItem) => { - return historyItem.slice(-10); - }) - ); - } - /** * Pushes a new history item to the history array * @public @@ -38,17 +33,17 @@ export class UmbCurrentUserHistoryStore { * @memberof UmbHistoryService */ public push(historyItem: UmbCurrentUserHistoryItem): void { - const history = this._history.getValue(); + const history = this.#history.getValue(); const lastItem = history[history.length - 1]; // This prevents duplicate entries in the history array. if (!lastItem || lastItem.path !== historyItem.path) { - this._history.next([...this._history.getValue(), historyItem]); + this.#history.next([...this.#history.getValue(), historyItem]); } else { //Update existing item - const newHistory = this._history.getValue(); + const newHistory = this.#history.getValue(); newHistory[history.length - 1] = historyItem; - this._history.next(newHistory); + this.#history.next(newHistory); } } @@ -58,6 +53,6 @@ export class UmbCurrentUserHistoryStore { * @memberof UmbHistoryService */ public clear() { - this._history.next([]); + this.#history.next([]); } } diff --git a/src/Umbraco.Web.UI.Client/src/core/modal/layouts/modal-layout-current-user.element.ts b/src/Umbraco.Web.UI.Client/src/core/modal/layouts/modal-layout-current-user.element.ts index df4e320f0c..2cc868caca 100644 --- a/src/Umbraco.Web.UI.Client/src/core/modal/layouts/modal-layout-current-user.element.ts +++ b/src/Umbraco.Web.UI.Client/src/core/modal/layouts/modal-layout-current-user.element.ts @@ -108,7 +108,7 @@ export class UmbModalLayoutCurrentUserElement extends UmbLitElement { } private async _observeHistory() { if (this._currentUserHistoryStore) { - this.observe(this._currentUserHistoryStore.getLatestHistory(), (history) => { + this.observe(this._currentUserHistoryStore.latestHistory, (history) => { this._history = history; }); }