Simplr
A wrapper library for @ngrx/store to use Redux concept in an easy way.
Maybe your desires:
- like to use Redux.
- but writing many actions and reducers is painful.
- very painful.
- to handle async actions is so painful.
- finding an easy way to use Redux concept.
- want to use Angular and RxJS.
Here Simplr comes into play.
Install
$ npm install --save @ngrx/core @ngrx/store ngrx-store-simplr
You also need to install Angular and RxJS.
Examples
Usage
Declare the app state interfaces.
// app/store/models/index.ts
Create reducer
and initialState
to import into app.module.ts
.
// app/store/reducer.ts ;;; ; ; ; ;
Edit app.module.ts
in order to use Simplr.
// app/app.module.ts ;;;
Create a service to dispatch to the store.
// app/services/counter.ts ;;;
Create a component to call service functions.
// app/containers/counter.ts ;;;
Done!
Did you notice that you wrote no actions and no reducers?
Demos
Details
dispatch
dispatch
function allows below sync and async writings.
this.simplr.dispatch'counter',state + 1 // callback// orthis.simplr.dispatch'counter', 1 // value// or this.simplr.dispatch'counter', Promise.resolvestate + 1 // callback in Promise// orthis.simplr.dispatch'counter', Promise.resolve1 // value in Promise// orthis.simplr.dispatch'counter', Observable.ofstate + 1 // callback in Observable// orthis.simplr.dispatch'counter', Observable.of1 // value in Observable
dispatch
function returns Observable result especially for testing.
// getting dispatched Action // getting updated current whole state // getting udpated current state under the key
dispatch
function allows to set some options.
// description option // timeout option (default: 1000 * 15) // retry option (default: 3)this.simplr.dispatch'counter', /* will try this HTTP request 10 times */, // logging option ... if set be true, the result will be shown on browser console.this.simplr.dispatch'counter',state + 1,