Redux Observable: Fire is the same epic for several activities

I want to remove the same contents of my epic in response to several actions. Something like that:

export default function uploadImage(action$, store) { return action$.ofType([ 'UPDATE_IMAGE, 'UPDATE_INTERESTS', 'UPDATE_LANGUAGE', ... ]) .switchMap(action => { Api.updateUser(); }) }; 

Is it possible?

+3
source share
2 answers

You are correct in your answer, ofType accepts an arbitrary number of types as arguments.

This is not currently documented, because in practice we almost always find the anti-pattern sign - not always, but it is very suspicious.

Until we have reliable guidance when it will be good or bad, we want to continue to prevent it from being used as a general rule, but of course, only you can judge whether it is suitable or not.

+5
source

From the looks of the docs, it seems like a variable number of arguments is required: https://github.com/redux-observable/redux-observable/blob/fd393a1adf359381c98ca494bc5dc2cac80f6d07/src/ActionsObservable.js#L26

0
source

Source: https://habr.com/ru/post/1012164/


All Articles