@novyk/sx-state
v9.0.0-beta.1
Published
Simple wrapper for BehaviorSubject with Immer integration.
Downloads
2
Readme
Angular state management with RxJS + Immer
Simple wrapper for BehaviorSubject with Immer integration.
StateValue automatically clones and freezes all states.
Installation
npm i @novyk/sx-state immer
Usage
Create SxState
export class AppComponent {
readonly data = new SxState<SomeValueInterface>(initialData);
}
Get value
this.data.value
Observe value
this.data.valueChanges
Set value
this.data.value = newData;
Produce new value using Immer
Works properly only with objects and arrays in the state.
More info about Immer: https://immerjs.github.io/immer/
this.data.produce(draft => {
draft.entry = newEntry;
});
Reset value to initial
this.data.reset();
Subscribe to another Observable
someObervable.subscribe(this.data.observer);
StateValue options
- noClone — do not clone all passed values
- noFreeze — do not freeze all passed values
new SxState<SomeValueInterface>(initialData, {
noClone: true,
noFreeze: true,
});