1.2.6 • Published 3 years ago

rxjs-reactive-state v1.2.6

Weekly downloads
3
License
MIT
Repository
github
Last release
3 years ago

rxjs-reactive-state: Reactive State with RxJS

RxJS powered state management library for Reactive Applications implementing observable store. Go to https://github.com/ramartinez7/angular-observable-store to see a full implementation in an use case with Angular (under construction).

Installation

npm i rxjs-reactive-state --save

Extension recommended: Auto Import, link: https://marketplace.visualstudio.com/items?itemName=steoates.autoimport

API

The classes are strongly-typed so you will have a lot of help of intellisense in VS Code. Exist two main classes: Store < T > and EntityStore<S extends EntityState, T> extends Store<S

  Store<T> where T is your state class, example: 

configure Store

typenamedescriptionExample
propertyobserver$Observable state
propertystateState value
propertylogActionsWheter log actions in console or not
methodchangeChange state valuethis.store.change({ products: products }), this.store.change(state => ({...}))
methodlistenListen to changes in statethis.store.listen(), this.store.listen(state => state.entities), this.store.listen('products'), this.store.listen('name', 'email')
methoddestroyCompletes the store subject.
  EntityStore<S extends EntityState<T>, T> extends Store<S>, you have to set the entity-state and entity class, example:

configure Entity Store

  EntityState<T> class looks like this

EntityState class

EntityStore class extends the properties and methods from Store class. Also,

typenamedescriptionExample
methodaddadds one or many items to the entities propertythis.store.add(product)
methodupdateupdates one property in the entities property, recieves a function with a boolean expression to find the element to update and the new elementthis.store.update(product => product.id === 1, new Product())
methodremoveremove an element from the entities property, recieves a function to find the elementthis.store.remove(product => product.id === 1)
methodexistsVerifies if an element exists in the entities property, recieves a function to search the elementthis.store.exists(product => product.id === 1)
methodsetActionSets the current action, recieves a string and by default starts with LOADING statusthis.store.setAction(ProductActions.GET_ALL);
methodsetStatusSet the state of the current action (LOADING, SUCCESS, FAILED, COMPLETE)this.store.setStatus(Status.FAILED)
  Actions and Status

To control changes to the state you can use Actions and Status, example:

Configure actions and status

Here you must use the Status enum imported from the package.

Submit an issue or fork the project to improve it. Soon I'll be posting more info about the implementation of the library. Go to https://github.com/ramartinez7/angular-observable-store to see a full implementation in an use case with Angular (under construction).

1.2.6

3 years ago

1.2.5

3 years ago

1.2.4

3 years ago

1.2.3

4 years ago

1.2.2

4 years ago

1.2.1

4 years ago

1.2.0

4 years ago

1.1.9

4 years ago

1.1.8

4 years ago

1.1.7

4 years ago

1.1.6

4 years ago

1.1.5

4 years ago

1.1.4

4 years ago

1.1.3

4 years ago

1.1.2

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago