Search code examples
angularngrx

What difference between select and without select in NgRx?


I have two ways usually use when I subscribe to a state of a store. Is it any difference between them (like performance or something)

constructor(private store : Store<MyState>){
    //1
    this.store.pipe(select(x=>x.myComplexObject)).subscribe(x=> {
        this.data = x;
    })
    //2
    this.store.subscribe(x=> {
        this.data = x.myComplexObject;
    })
}

Solution

  • Both are the same. But, I would suggest moving to selectors because these have several advantages:

    • multiple selectors can be combined
    • easy to test
    • performant because it's memoized

    https://ngrx.io/guide/store/selectors