Angular @ngrx/store Side-By-Side Code Comparison

Allen Kim
Digital-Heart
Published in
2 min readFeb 23, 2018

Here I compare two ways of displaying Todo between using @ngrx/store and without using it.

Assuming readers understand Angular HTTP call, from below here, I want to compare files side-by-side, so that you can see what difference they have.

app.module.ts

With @ngrx/store, we need to import reducers and effects at the app root level.

left: normal, right: w/ ngrx/store

app.component.ts

Without @ngrx/store, data is retrieved from a service.

Unlike a normal service, with @ngrx/store is todos$ are retrieved from store.select after calling store.dispatch(getTodos()), which is linked to getTodos$ property in todos.effetcs.ts.

left: normal, right: w/ ngrx/store

app.component.html (the same)

todo.component.ts(the same)

todo.component.ts(the same)

todos.service.ts(the same)

todos.reducters.ts

It defines pure functions which implement action with two parameters; type, and payload.

left: normal, right: w/ ngrx/store

todos.effects.ts

It defines a function to be executed when store.dispatch is called.

left: normal, right: w/ ngrx/store

This is my first trial of understanding @ngrx/store, and I might not have clearly understand the benefits of using @ngrx/store. However, I wish this side-by-side comparison is helpful to others.

Cheers

--

--