Skip to content

Commit 17968eb

Browse files
committed
feat(observable): adds previous value to broadcast
1 parent f5ab7c2 commit 17968eb

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/utils/observable.utils.ts

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export type Observer<T> = (data: T) => void;
1+
export type Observer<T> = (next: T, prev?: T) => void;
22
export type UpdateFunction<T> = (state: T) => T;
33
export type Updater<T> = T | UpdateFunction<T>;
44

@@ -72,6 +72,17 @@ export class ObservableState<T> extends Observable<T> {
7272
private readonly _mutable: boolean;
7373
private _state: T;
7474

75+
/**
76+
* Notifies all observers with optional data and previous state.
77+
*
78+
* @protected
79+
* @param {T} data - The new data to be sent to observers.
80+
* @memberof Observable
81+
*/
82+
protected _notify(data: T) {
83+
this._observers.forEach(observer => observer(data, this._state));
84+
}
85+
7586
/**
7687
* Gets the current state of the observable.
7788
*

0 commit comments

Comments
 (0)