4 ms·
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 to
by babbeloski 10y ago
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.
- tacone 10y agoOf course: https://github.com/erikras/ducks-modular-redux 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.
- tokenizerrr 10y agoI 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.
- kumaraman 10y agoI 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 http://redux.js.org/docs/api/combineReducers.html
- jamra 10y agoThat would combine your reducers into one. I believe he was referring to putting action creators in the same file as their associated reducers.
- rattray 10y agoI do this as well in small projects, then split it out when things get big (eg; >1000 line file).
- tfb 10y agohttps://github.com/loggur/react-redux-provide 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.
- clarus 10y agoIt 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 http://guide.elm-lang.org/architecture/index.html . The Update part groups both the definition of the actions and the reducers.