4 ms·
Hi, thanks for your reply! I've had a look at some of the higher-level abstractions for Redux [1], but none of them really appealed to me. I'm just looking for
by nathan_f77 8y ago
Hi, thanks for your reply! I've had a look at some of the higher-level abstractions for Redux [1], but none of them really appealed to me. I'm just looking for something magical and opinionated so that I can write less code, so I might even try to write my own abstraction. I want to see if it's possible to automatically generate actions and action creators just based on the reducer. Maybe a special way of writing reducers, or maybe leverage the type system and write a babel plugin.
[1] https://redux.js.org/introduction/ecosystem#higher-level-abstractions https://redux.js.org/introduction/ecosystem#higher-level-abs...
- acemarke 8y agoFunny you should mention that :) There's a lot of existing libraries out there that will indeed generate action creators, reducers, etc (see my Redux addons list [0] for examples). One of the most interesting ones I've seen is Eric Elliott's `autodux` project [1], which does some clever bits of handling inside a `createSlice()` function. Earlier this year, I put together a new project called `redux-starter-kit`] [2]. Its goal is to simplify several common use cases with Redux usage, including store setup, reducer definitions and immutable update logic, and default behavior out of the box. While we don't plan to add these things to the Redux core itself, `redux-starter-kit` is an official Redux-branded library, and we're going to start encouraging that people use it in most situations. We just added a `createSlice` function to `redux-starter-kit`, based on the `autodux` approach. I'd encourage you to try it out, as it does _exactly_ what you're asking for. I'd also really appreciate some feedback on how well it works, and any additional ideas for things the starter kit should include! [0] https://github.com/markerikson/redux-ecosystem-links https://github.com/markerikson/redux-ecosystem-links [1] https://github.com/ericelliott/autodux https://github.com/ericelliott/autodux [2] https://github.com/reduxjs/redux-starter-kit https://github.com/reduxjs/redux-starter-kit
- nathan_f77 8y agoautodux looks amazing, thanks for the link! I hadn't seen that before, and that's exactly what I'm looking for. Looks like there will be a bit of work to add support for Flow and Immutable.js, but I might look into that. redux-starter-kit looks great too!
- acemarke 8y agoSure. Also, just as an FYI, because a large number of people aren't aware this is possible: you can pass an object full of action creators to `connect` instead of a `mapDispatch` function. This simplifies the use of `connect`, like: export default connect(mapState, {addTodo, toggleTodo})(TodoList); We're about to add a whole big section on dispatching and action creators to our new React-Redux docs site at https://react-redux.js.org https://react-redux.js.org - keep an eye out for that. Until then, check out Dave Ceddia's post at https://daveceddia.com/redux-mapdispatchtoprops-object-form/ https://daveceddia.com/redux-mapdispatchtoprops-object-form/ for an explanation.