3 ms·
I think a good bit of is it the fact that the example code on the redux website is _extremely_ verbose, and that most people who stick with redux for the long h
by Octoth0rpe 7y ago
I think a good bit of is it the fact that the example code on the redux website is _extremely_ verbose, and that most people who stick with redux for the long haul end up using a variety of shortcuts that make their code significantly terser yet still readable. I'm in the middle of writing a short presentation for my local jsx meetup on a set of simple rules for writing good redux code. As part of the presentation, I'm providing two repos for a webapp, one with the store written using the exact code style used by the redux website, and a second one using my suggested rules and IMO the result is pretty dramatic. Until I got to writing the 'official' style version of the app, I had forgotten just how verbose redux can be. I would NOT want to use redux if I was sticking to the 'official' example style.
- acemarke 7y agoI'd like to see that presentation. Got a link to the slides? And yes, as part of our planned docs revamp, we're going to write example code that is much shorter, including use of Redux Starter Kit by default and use of the "ducks" pattern and/or "feature folders" by default. Could you leave a comment at https://github.com/reduxjs/redux/issues/3313 https://github.com/reduxjs/redux/issues/3313 with some notes on how the current docs examples are too verbose?
- Octoth0rpe 7y ago> I'd like to see that presentation. Got a link to the slides? If you're willing to wait a week, I could share. I'm really not ready to share it as is (still working on the code). > Could you leave a comment at https://github.com/reduxjs/redux/issues/3313 https://github.com/reduxjs/redux/issues/3313 with some notes on how the current docs examples are too verbose? Yes, I could do that, but again I'll need at least a couple of days. It's a crazy week for me. If you want a _quick_ example, here's one from the 'actions' section of the basic tutorial: ------ function addTodo(text) { return { type: ADD_TODO, text } } ------ I would advocate writing this as: const addTodo = (payload) => ({ type: ADD_TODO, payload, }); ------- 4 lines instead of 6, just as readable to me. And frankly, I'd consider doing that as a 1-liner since there's only two attributes in the action anyway. Where I work, we have a semi-official rule of 'newlines for attributes if there are more than 3, or if the line length > 80', so our policy would write this action creator as a single line. export const addTodo = payload => ({ type: ADD_TODO, payload });
- acemarke 7y agoSure, no worries. Ping me on Twitter (@acemarke) when you've got it posted, or just leave a comment in that issue and I'll see it. For that example, it's a combination of: - ES6 was barely finalized when the docs first came out - Questions of clarity and familiarity with arrow functions. Fortunately, with Redux Starter Kit, you don't even have to write action creators or action types by hand any more :)
- efdee 7y agoconst addTodo = action(ADD_TODO);