Hacker News new | ask | show | jobs
by shantly 2366 days ago
The first thing I do when teaching someone Redux is tell them that Action just means Event, and "action creator" just means an event dispatcher, which is to say, any function that dispatches an event. Naming the least-active part of the system Action is really confusing—it doesn't even describe an action, necessarily, nor force any action—and naming a function that happens to emit an event an action creator as if it's creating actions (huh? what does that mean?) is misleading.
1 comments

This is specifically due to the fact that the original Flux implementation labeled these objects as "actions", and Redux was designed as a Flux Architecture implementation:

https://github.com/reduxjs/redux/issues/891

Is it too late to change it? I’ve worked at a few agencies for a lot of companies using Redux. Teaching people to think of actions as events instead of setters has been a huge pain point.

I would seriously suggest just find and replace the word action with event within Redux and the docs. Maybe have one page explaining the history behind this.

We certainly aren't changing the actual name "action" to "event" in the code or docs.

_However_, we _do_ have a new "Style Guide" docs page, and in that we tell people to "Model Actions As 'Events', Not 'Setters'":

https://redux.js.org/style-guide/style-guide#model-actions-a...

We'll be adding more pages with info on that topic as part of our ongoing core docs rewrite. I'd suggest pointing people to this style guide entry, as well as these excellent presentations that go into more detail:

- https://github.com/dmmulroy/talks/blob/master/event-driven-r...

- https://youtu.be/K6OlKeQRCzo?t=2626 (video) / https://rangle.slides.com/yazanalaboudi/deck#/ (slides)

> We certainly aren't changing the actual name "action" to "event" in the code or docs.

That's what I think should be done, with a page noting that historically they were called actions but events is a better name. I think it's the right move to help people understand Redux better and write better Redux code.

There are still people learning Redux for the first time today and the current docs and the name "action" seems to push them towards writing imperative code.

IMO imperative actions are the biggest issue people have using Redux.

I guess a first step in the right direction might be just redoing the docs in an event style. e.g. The counter example would use events like "clickedIncrement" and "clickedDecrement".

As long as I'm giving feedback on stuff, I really like createReducer (builder api) and createAction from Redux Toolkit. I think createSlice encourages the action = reducer anti-pattern.