Skip to content
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

Support slice reducers #147

Closed
mauron85 opened this issue Mar 5, 2017 · 8 comments
Closed

Support slice reducers #147

mauron85 opened this issue Mar 5, 2017 · 8 comments

Comments

@mauron85
Copy link

mauron85 commented Mar 5, 2017

Some reducers need to access state from different slice of state as written in
http://redux.js.org/docs/recipes/reducers/BeyondCombineReducers.html#sharing-data-between-slice-reducers

Example

const undoableDeliveriesReducer = undoable(deliveriesReducer);
const undoableRoutesReducer = undoable(routesReducer)

export default function entitiesReducer(state = defaultState, action) {
  return {
    couriers: couriersReducer(state.couriers, action),
    deliveries: undoableDeliveriesReducer(state.deliveries, action),
    routes: undoableRoutesReducer(state.routes, action, state.deliveries),
  };
}

Currently undoable only pass state and action to actual reducers, so in case of routesReducer state.deliveries will be null. Fix should be easy.

@davidroeca davidroeca mentioned this issue Mar 15, 2017
@davidroeca
Copy link
Collaborator

Hi @mauron85 I just made a pull request for this issue

@mauron85
Copy link
Author

Nice. In meantime I realised that redux-undo is not suitable for my use case as I need to undo actions, not just revert state of the UI.

@davidroeca
Copy link
Collaborator

@mauron85 what's the difference in that case? If your reducer is undoable, then the state changes associated with the action will be undone. The action will be undone, no?

If you're referring to thunk actions (actions that have side-effects that result in more actions), you can look into filtering.

@mauron85
Copy link
Author

mauron85 commented Mar 16, 2017

I also need to undo action on the server, but I cannot determine which action it was from state change. And redux-undo, only store state changes, not action types/names which lead to those changes. Hopefully I expressed myself clearly. :-)

@davidroeca
Copy link
Collaborator

I see, so not a redux action but an API call. Yeah, undoing side effects outside the redux store is outside the scope of this library. I assume there would have to be specific logic for each back-end call to undo the call. Though in either case I don't think there would be a simple way to undo a deletion

@mauron85
Copy link
Author

mauron85 commented Mar 16, 2017

Yes, https://github.com/powtoon/redux-undo-redo is doing it in custom middleware and revertingActions. Anyway for state/UI only undos, your module is perfect.

@davidroeca
Copy link
Collaborator

Ah interesting, definitely provides a backend-compatible solution at the cost of usability. I'm thinking this sort of functionality could be incorporated into this library as a config option. I'll look into it when I have the time

@davidroeca
Copy link
Collaborator

Created a new issue (#150) and closing this one since the PR has been merged

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants