Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular2 / ngrx and API calls

Tags:

angular

ngrx

I have been exploring ngrx (ngrx/store) lately. I have studied some classic examples on the net (a todo app). Great example. Now I am want to take it to the next level by letting my ngrx app do some API calls. Are there examples or guidelines how to setup a ngrx (redux) app to invoke and handle api calls?

It's my understanding that api calls within the context of my redux app are side-effects (functional programming paradigm). I am wondering how/where to implement API calls in a redux app.

like image 537
user2120188 Avatar asked Sep 09 '16 16:09

user2120188


People also ask

When should you not use NgRx?

When should you not use NgRx? Never use NgRx if your application is a small one with just a couple of domains or if you want to deliver something quickly. It comes with a lot of boilerplate code, so in some scenarios it will make your coding more difficult.

Is NgRx same as RxJS?

Ngrx is a group of Angular libraries for reactive extensions. Ngrx/Store implements the Redux pattern using the well-known RxJS observables of Angular 2. It provides several advantages by simplifying your application state to plain objects, enforcing unidirectional data flow, and more.

What is the difference between Redux and NgRx?

NgRx, which is the Angular version of Redux for React is for State Management. In React, state management can get complicated, and Redux is there to help. For Angular, this should not be the case as everything is synced due to two way data binding.

Does NgRx improve performance?

Luckily, NgRx provides state and action sanitizers that can be used to clean up your data to reduce the amount of state (for example, multiple arrays with thousands of items) to improve the performance of the devtool.


1 Answers

Ngrx has its own library for side-effects ngrx/effects Some more information:

  1. Introduction: https://github.com/ngrx/effects/blob/master/docs/intro.md
  2. tutorial: https://stackoverflow.com/a/39626187/806963

There are not much resource about this library. You can find more here:

  1. https://gitter.im/ngrx/store?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge
like image 65
Stav Alfi Avatar answered Sep 24 '22 12:09

Stav Alfi