Simple wrapper for BehaviorSubject with Immer integration.
StateValue automatically clones and freezes all states.
npm i @novyk/sx-state immer
export class AppComponent {
readonly data = new SxState<SomeValueInterface>(initialData);
}
this.data.value
this.data.valueChanges
this.data.value = newData;
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;
});
this.data.reset();
someObervable.subscribe(this.data.observer);
- noClone — do not clone all passed values
- noFreeze — do not freeze all passed values
new SxState<SomeValueInterface>(initialData, {
noClone: true,
noFreeze: true,
});