Reputation: 1222
I have a problem with ngrx store, a strange problem! The select operator does not call the callback function, and when I subscribe to the store I can see the state of the app (the initial state and the modified state)
export class PatternsViewComponent implements OnInit {
patternsCategoryList$:Observable<string[]>;
// selectedPatternCategory$:Observable<string>;
constructor(private store: Store<ApplicationState>) {
this.store.select(mapToDataToSources);
}
ngOnInit() {
}
}
export function mapToDataToSources(state:ApplicationState) :String[]{
debugger;
console.log(state.uiStoreData.patterns);
return state.uiStoreData.patterns;
}
Upvotes: 0
Views: 1951
Reputation: 15191
Be careful with setups like that.
For this purpose, nrgx has createSelector method. you should use that one to create selectors for parts of the store that you want to use later through store.select(whateverSelector).
Bear in mind, store.select doesn't select parts of the store directly but actually goes through selectors that createSelector returns (which handles transforming parts of the store into Observbles).
Upvotes: 2
Reputation: 14365
Because your observable (the result of the select) is cold, that is nothing subscribed to it.
Try:
this.store.select(mapToDataToSources).subscribe(); // added .subscribe()
If you use the observable in a view, it is enough that you pipe it through async pipe and the subscribe becomes redundant.
Upvotes: 1