ForbesLindesay / redux-optimist

Optimistically apply actions that can be later commited or reverted.
MIT License
776 stars 39 forks source link

Action implementation #6

Closed joecritch closed 8 years ago

joecritch commented 8 years ago

I have two questions about implementing optimistic actions:

(1) For the asynchronous ADD_TODO action, is it only ADD_TODO that needs to be initially called by my own action creator? And the middleware handles the corresponding _COMPLETED and _FAILED dispatches?

(2) How would the api.js middleware handle multiple action types? (E.g. DELETE_TODO?) Would I need a separate middleware for every action type?

Thanks in advance.

ForbesLindesay commented 8 years ago
  1. Yes, the action creators should create actions for api calls, then the middleware creates actions for success/failure
  2. The middleware is something you write yourself, so it's up to you. You could have a generic API_CALL action type, and handle that in middleware. You could add a property to your api call actions and look for that, rather than a type, in your middleware.
joecritch commented 8 years ago

Thanks, this is working well so far. I'll try and get an example put together for future reference.

ForbesLindesay commented 8 years ago

Thanks, I'll close this issue, but feel free to keep commenting or open a new issue if you have more questions/suggestions.