I am developing functionality where dispatch is not needed if loading or loaded values in state are true. I am facing issues with checking BOTH values in the store before dispatching. Is there a way to combine two selectors before dispatching action?
I need can have two possible forms of a State:
State = {
list: [],
loading: true,
loaded: false
}
or
State = {
list: [],
loading: false,
loaded: true
}
I am trying to do it with two selectors (method in my component):
checkStore() {
return this.store.select(getLoading).pipe(
tap(loading => {
if (!loading) {
this.store.select(getLoaded).pipe(
tap(loaded => {
if (!loaded) {
this.store.dispatch(fetchList({ payload: {something} }));
}
}),
take(1)
);
} else {
this.store.dispatch(fetchList({ payload: {something} }));
}
}),
take(1)
);
}
And then calling such method in ngOnInit() As i see nothing is being dispatched in this way. Maybe you have suggestions for implementing such functionality?