Hacker News new | past | comments | ask | show | jobs | submit login

At work I've started keeping the reducer in the actions file, anyone else do that? This way they can share the same const declarations, and you don't have to toggle between two files when most actions / reducers are pretty small.



Of course: https://github.com/erikras/ducks-modular-redux

The potential reason not to do that is that more than a reducer may listen for a given action, even though I guess it's more an exception than the norm.


https://github.com/loggur/react-redux-provide

This allows you to encapsulate all of your Redux actions/reducers/etc into standalone "providers". It decouples pretty much all of your React components (UI) from your Redux logic (models/controllers), which maximually separates your concerns and makes it trivial to reuse anything anywhere. It also allows you to instantly swap databases and/or websocket implementations.


I originally tried this but then discovered combineReducers() this will allow you to organise your reducers into a single import. I found it a more sane way to organise all of my reducers, as the majority of them were small. Here's a link for API http://redux.js.org/docs/api/combineReducers.html


That would combine your reducers into one. I believe he was referring to putting action creators in the same file as their associated reducers.


It seems that this is also the way of doing things in Elm (from which Redux is inspired): http://guide.elm-lang.org/architecture/index.html . The Update part groups both the definition of the actions and the reducers.


I started doing that pretty soon after starting with Redux, with some other tweaks to make them even more tightly coupled. It worked well for me, but I assume there is a reason not do that. However, I never figured that one out.


I do this as well in small projects, then split it out when things get big (eg; >1000 line file).




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

Search: