Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I just started with redux-saga which uses ES6 generators to handle app control flow.

After first impressions, I'd say it's worth a look if you're running into anything near as complicated as talked about here. It's very easy to reason about and test. gaearon - the creator of redux - seems to approve of it as well.

https://github.com/yelouafi/redux-saga



I just wrote our API layer with redux-saga too, I started with thunks but I didn't like dispatching thunks and actions, also it was hard to reason about flow and side effects: If I update my search form, the results need to be updated, but the action is "update form", not "update form and update search results", the search result update is a side effect more than something that should be actually fired from the update form.

Saga is making side-effects (workflows) possible by subscribing to events.

So in this case I have a saga waiting for 'SEARCH_FORM_UPDATE', then it waits for 300ms, then starts the ajax request flow: a request start action, then a request complete action (or request error).

The code reads almost like synchronous code once you understand yield.

It also allows you to listen to actions that you do not control: we wanted to do something whenever a specific redux-router action happened. You can't do this with thunks, we would have needed a middleware to do this. With sagas you can simply hook up a flow to the action.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: