Skip to content
This repository has been archived by the owner on Feb 21, 2023. It is now read-only.
/ rxer Public archive

Angular state management with RxJS+Immer

Notifications You must be signed in to change notification settings

navix/rxer

Repository files navigation

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,
});

About

Angular state management with RxJS+Immer

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published