I am using redux, redux-observable.
I have the following
import { EMPTY, Observable } from "rxjs";
const setCurrentDatastoreIdEpic = (action$, state$): Observable<any> => action$.pipe(
ofType(DatastoreActions.setCurrentDatastoreId),
map((action: {payload: {datastoreId: string}}) => {
if(action.payload.datastoreId) {
return ItemsActions.getItemsListRequest({
datastoreId: action.payload.datastoreId,
page: 1,
});
} else {
return EMPTY;
}
})
);
But everytime I go in the else I have
Uncaught Error: Actions must be plain objects. Use custom middleware for async actions.
But they say to use EMPTY if there is no action dispatched.
I also tried Observable.empty()
but it say that empty do not exist in Observable (and this way is deprecated from what I saw)
return ({ type: 'NO DATASTORE SELECTED'})
It does work, but is it a good practice ? – Peugia