Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NGRX 5 piped selector

In this article on medium.com (13 Feb.) regarding NGRX 5 they present pipeable selectors. This reminds me on reading about pipeable selectors in rxjs where they could not just be justified by 'its pure function, bro', but also by the way functions could be declared and reused in different occurences without using map every time to then call a letable function.

So i can agree, that this is a good thing in rxjs, but why would we need this in ngrx - for selectors. The linked article shows the following example:

import { Store, select } from '@ngrx/store';
import { Observable } from 'rxjs/Observable';

interface AppState {
  count: number;
}

@Component({
  selector: 'my-app',
  template: `
    <button (click)="increment()">Increment</button>
    <div>Current Count: {{ count$ | async }}</div>
    <button (click)="decrement()">Decrement</button>

    <button (click)="reset()">Reset Counter</button>
  `
})
export class MyAppComponent {
  count$: Observable<number>;

  constructor(private store: Store<AppState>) {
    this.count$ = store.pipe(select('count'));
  }
}

So we now call store.pipe(select(...)); instead of store.select(Selector); - where are the gains? why should i change my code to use this behaviour or at least start to use pipeable selectors?

like image 969
SchreiberLex Avatar asked Apr 12 '18 07:04

SchreiberLex


1 Answers

In NgRx 7 this deprecation is been reverted - see changelog.

like image 53
timdeschryver Avatar answered Oct 25 '22 23:10

timdeschryver