Files
Umbraco-CMS/src/Umbraco.Web.UI.Client/libs/observable-api/unique-object-behavior-subject.ts
2023-01-23 14:28:44 +01:00

27 lines
1.1 KiB
TypeScript

import { UniqueBehaviorSubject } from "./unique-behavior-subject";
/**
* @export
* @class UniqueObjectBehaviorSubject
* @extends {UniqueBehaviorSubject<T>}
* @description - A RxJS UniqueObjectBehaviorSubject which deepFreezes the object-data to ensure its not manipulated from any implementations.
* Additionally the Subject ensures the data is unique, not updating any Observes unless there is an actual change of the content.
*
* The UniqueObjectBehaviorSubject provides methods to append data when the data is an Object.
*/
export class UniqueObjectBehaviorSubject<T> extends UniqueBehaviorSubject<T> {
/**
* @method append
* @param {Partial<T>} partialData - A object containing some of the data for this Subject.
* @description - Append some new data to this Object.
* @example <caption>Example append some data.</caption>
* const data = {key: 'myKey', value: 'myInitialValue'};
* const mySubject = new UniqueObjectBehaviorSubject(data)
* mySubject.append({value: 'myNewValue'})
*/
update(partialData: Partial<T>) {
this.next({ ...this.getValue(), ...partialData });
}
}