BigAB / use-epic

Use RxJS Epics as state management for your React Components
MIT License
46 stars 4 forks source link

can we make the dispatch globally? #23

Closed aaronkzhou closed 3 years ago

aaronkzhou commented 3 years ago

Is your feature request related to a problem? Please describe. A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

scenario: I wanna dispatch different actions from different Epic.

const [, dispatchLogin] = useEpic(loginEpic)
const [, dispatchActivate] = useEpic(activateEpic)

dispatchActivate({type1,payload1})
dispatchLogin({type1,payload1})

above are different dispatch, and cannot be access and catch globally

Describe the solution you'd like A clear and concise description of what you want to happen.

combine all the epics and use single dispatch like `redux-observable` combineEpics

Describe alternatives you've considered A clear and concise description of any alternative solutions or features you've considered.

Additional context Add any other context or screenshots about the feature request here.

BigAB commented 3 years ago

I don't think I want to dispatch globally, you could probably use the "deps" to pass a function to all the epics that you use for globally handling errors. You could probably wrap epics in a function that pipes all actions to some global observable (or function or whatever) with something like const myEpic = createEpic((action$, state$) => ...).

It may be more appropriate to use redux-observable if you want that kind of behavior though.