4 ms·
Mark, your writings have really helped me to understand the redux landscape (inasmuch as I do), so I'd be curious to know what you think of this, if you've seen
by gimboland 7y ago
Mark, your writings have really helped me to understand the redux landscape (inasmuch as I do), so I'd be curious to know what you think of this, if you've seen it: https://www.youtube.com/watch?v=JmnsEvoy-gY https://www.youtube.com/watch?v=JmnsEvoy-gY ("Good Action Hygiene with NgRx", Mike Ryan, NGConf April 2018)
The context is ngrx but the territory is familiar. Two things struck me in particular: one (the key point of the talk) is the idea that actions should be named as effects not intentions. The other (which I loved) is the idea of having action types that look like (say) "[Todo List Page] Add Todo Clicked" rather than "ADD_TODO" — it certainly makes the history more legible in redux-devtools. (I'm unsure how to name my consts then, though; I'm going with TODO_LIST_PAGE_ADD_TODO_CLICKED but it's very verbose; in the video it looks like he's not bothering with consts at all, and is just using the strings directly at dispatch and reduce time, and maybe there's something in that — the strings are specific enough that there'd be no scope for confusion, I guess.)
Just wondered what you thought of all this? I've read your idiomatic redux series, but maybe your thoughts have moved on since then...
- acemarke 7y agoI have that talk bookmarked to watch, but my bookmarks queue is like 600+ deep at this point :) Just going by your summary: Yeah, I do find it interesting how some different parts of the community have chosen to format their action strings differently. Redux itself literally doesn't care, of course - the only requirement is that `action.type` not be undefined. As I said in "The Tao of Redux, Part 1: Implementation and Intent" [0], one of the main intents behind Redux is that the action log should be a literally readable history of what's going on in your app with semantic meaning behind each name. You _could_ have a single `"SET_DATA"` action, but that doesn't tell me anything about what's going on. The Redux docs originally went with the SCREAMING_SNAKE_CASE string format just because that's the common programming world convention for constant values. The naming in the docs also tends towards matching how you would name the action creator, ie, `"TOGGLE_TODO"` -> `toggleTodo()`. Those are perfectly legitimate choices to make, but definitely not the only possible ways to do it. I've seen plenty of other variations over the years, usually in the form of some "domain" string + the "event" name. For Redux Starter Kit, we've gone with a '/'-separated string, such as `"todos/addTodo"`. The end user is still supplying both parts (via the slice `name` field and the user-defined reducer function name). So, the Angular-ish convention of `"[Some Domain] Some Event"` is perfectly fine, and very readable. Either way, it doesn't matter what you actually name the _variable_ that points to that action type. One of the most interesting variations I've seen on this is Slack, which apparently uses entire _sentences_ as their action types, each including a unique numeric ID [1]. Finally, yes, we would generally recommend treating actions semantically as "events in the app", not "setters at a distance". Again, the Redux store itself doesn't care, but the "events" mental modeling promotes dispatching fewer total actions and having multiple reducers independently responding to a given action [2]. We'll emphasize this more in the upcoming docs revamp. Glad to know my writing has helped! Lemme know if you've got any other questions. [0] https://blog.isquaredsoftware.com/2017/05/idiomatic-redux-tao-of-redux-part-1/ https://blog.isquaredsoftware.com/2017/05/idiomatic-redux-ta... [1] https://twitter.com/erikras/status/1153350835738468363 https://twitter.com/erikras/status/1153350835738468363 [2] https://redux.js.org/faq/actions#is-there-always-a-one-to-one-mapping-between-reducers-and-actions https://redux.js.org/faq/actions#is-there-always-a-one-to-on...
- gimboland 7y agoHey Mark, thanks for taking the time to reply. I hear you on the bookmarks queue! :-) All makes sense. I hadn't heard of RSK until I read this comment, but I've now seen your other comment in this thread which mentions it[0], watched the "State of Redux" talk referenced there and I'm excited to try it out. Cheers! [0] https://news.ycombinator.com/item?id=21254525 https://news.ycombinator.com/item?id=21254525