-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Solution Feedback: redux-subspace #41
Comments
The proposed solution breaks encapsulation on multiple occasions. To start with, there is this action creator which belongs to the export const getGif = () => (dispatch, getState, api) => {
dispatch(loading())
api.getRandomGifUrl()
.then((url) => dispatch(setGifSrc(url)))
.then(() => dispatch(increment()))
} How can Then if I look at the export default (state = initialState, action) => {
switch (action.type) {
case TOGGLE:
return { ...state, useMultiplier: !state.useMultiplier }
case INCREMENT: {
const increment = state.count >= 10 && state.useMultiplier ? 2 : 1
return { ...state, count: state.count + increment }
}
default:
return state
}
} Again, it's dependent on another component and cannot be published independently. Fixing it would start by removing
The saga is the glue that makes it all work. If you will, in DDD terms, it listens to events from two bounded contexts (button and randomGif) and converts them to a command for the third bounded context (counter). None of these bounded contexts know or depend on the others, nor should they. This saga would not be part of any component, or if you must place it in one, it would be part of the application component (or whichever parent contains these participating components). Of it could be part of a CounterWrapper HOC. |
I have submitted a PR with a solution using redux-subspace.
Any feedback is welcome.
The text was updated successfully, but these errors were encountered: