When to use ngrx/effect in angular2

Viewed 3746

I have an anuglar2 project that communicates with an api. Recently, I decided to integrate ngrx/store to maintain the state of the components, and follow the dump-smart component architecture. But then while moving on, I read about ngrx/effect which can be used upon the api requests.

And here my question comes, why should I use the ngrx/effect library, over just calling the corresponding function in my service from my container component to perform the api request and on success dispatch action to save the returned values in my store.

3 Answers

I honestly believe that the majority of apps that are using ngrx shouldn't be. Stores solve problems that most forms based applications don't encounter.

Have a look at a library I am working on that gives the push based data flow benefits of a store but makes it incredible simple to setup and reason about without any of the ridiculous amount of boilerplate involved with ngrx.

https://github.com/adriandavidbrand/ngx-rxcache

It is based on RxJs Behaviour Subjects and gives you all the benefits of push based data flow and still allows you to use the dumb-smart component architecture.

I have redone the official ngrx demo application in it here

https://stackblitz.com/edit/github-tsrf1f

If you compare it to the official ngrx demo app at

https://stackblitz.com/github/ngrx/platform/tree/61cbfe537f9df8cef3dd4a6ee0b8f483e49653f4

You will see how much simpler it is to setup and work with.

Related