diff --git a/src/Umbraco.Web.UI.Client/src/libs/observable-api/basic-state.ts b/src/Umbraco.Web.UI.Client/src/libs/observable-api/basic-state.ts index 8f6e2bc29d..8adc9e15f3 100644 --- a/src/Umbraco.Web.UI.Client/src/libs/observable-api/basic-state.ts +++ b/src/Umbraco.Web.UI.Client/src/libs/observable-api/basic-state.ts @@ -16,17 +16,55 @@ export class UmbBasicState { this.destroy = this._subject.complete; } + /** + * @method asObservable + * @return {Observable} Observable that the State casts to. + * @description - Creates a new Observable with this State as the source. Observe this to subscribe to its value and future changes. + * @example Example observe the data of a state + * const myState = new UmbArrayState('Hello world'); * - */ + * this.observe(myState, (latestStateValue) => console.log("Value is: ", latestStateValue)); + */ public asObservable: BehaviorSubject['asObservable']; + + /** + * @property value + * @description - Holds the current data of this state. + * @example Example retrieve the current data of a state + * const myState = new UmbArrayState('Hello world'); + * console.log("Value is: ", myState.getValue()); + */ public get value(): BehaviorSubject['value'] { return this._subject.value; }; + + /** + * @method getValue + * @return {T} The current data of this state. + * @description - Provides the current data of this state. + * @example Example retrieve the current data of a state + * const myState = new UmbArrayState('Hello world'); + * console.log("Value is: ", myState.value); + */ public getValue: BehaviorSubject['getValue']; + + /** + * @method destroy + * @description - Destroys this state and completes all observations made to it. + */ public destroy: BehaviorSubject['complete']; - + /** + * @method next + * @param {T} data - The next set of data for this state to hold. + * @description - Set the data of this state, if data is different than current this will trigger observations to update. + * @example Example retrieve the current data of a state + * const myState = new UmbArrayState('Good morning'); + * // myState.value is equal 'Good morning'. + * myState.next('Goodnight') + * // myState.value is equal 'Goodnight'. + */ next(newData: T): void { if (newData !== this._subject.getValue()) { this._subject.next(newData);