ActionCreators => Actors?
Is it just me, or is the name "ActionCreator" a bit clumsy – and also slightly inaccurate considering its purpose in the Flux architecture? There has been some confusion circulating about the purpose of this type of components, and I think that's mainly because of its name.
An ActionCreator is responsible for creating an Action, but also for passing the action along to the Dispatcher. Now, the name of the component does not encompass the latter responsibility. So maybe ActionCreators should have a different name?
I find "Actor" to be a better name. Not just is it an easier word, I also consider it more precise. As we know, an Actor is someone or something that acts on a system, and it does so by means of Actions. Also, an Actor is the origin of a performed Action, i.e., Actors also create Actions. This definition fits in nicely with the responsibility of today's ActionCreators.
Conceptually, the coupling between the Actor and the Dispatcher is also pretty easy to explain. When an Actor performs an Action on a system, it does so by way of a channel. In this case, the channel is the Dispatcher.
So, what do you guys think? Actors or ActionCreators? Or maybe someone else has a better suggestion?
Internally we named our ActionCreators Intents for the same reasons (admittedly risking confusion with Android Intents).
Yeah, the name is probably a little clumsy. There's a lot of information out in the world now about action creators, so I doubt we want to create more confusion by changing the name now.
The history here is that we used to call the FooActionCreators module just simply FooActions, but this led to some confusion -- the methods were seen as the action instead of the object they create and pass to the dispatcher. In the summer of 2014 Jing Chen and I were putting together a presentation for ForwardJS and we wanted to dispel this confusion. We came up with ActionCreator a day or two before the conference. Now we're a bit stuck with it.
I'll think about it, though. Thanks for bringing it up.
I think Actor or Intent is a fine name for these methods, and I encourage you to do what you think is best for your teams. There are connotations to both that I might quibble with, however.
Actor tends to be something with agency, which these methods do not really have.
Intent leans toward thinking of the methods like setters, and this is an easy trap to fall into. The actions are reporting on something that happened in the real world -- the user clicked, the server responded, etc -- and the Flux stores need to respond to this real world change. Intent implies that the server "intends" for something to happen in the client side application, which is not really true -- it's the store that needs listen to actions and respond. The actions are more like a newspaper, reporting on the real world. Thinking more in these terms, I've switched to naming all my action types in the past tense.
See also this conversation I had with @abdullin, who is the person who first emphasized this "past" quality of actions. https://gist.github.com/abdullin/5953ab4f5eae0a7fc8f9
I would agree that using term "actor" to describe "action creator" can cause a lot of confusion for some folks. In Erlang (and inspired platforms), actors are the core building block with very strong connotations. People keep state and logic inside actors. Meanwhile in pre-Relay React/Flux I observe that action creators tend to be stateless and simple.
It is in the nature of people to try to find patterns in things and follow them. If "action creators" were called "actors", a lot of people could start putting logic and state in them.
I found some success in using term "event creator", while describing "action creator" in Flux to the folks with the event-driven background. "Event" has a strong meaning in that context: it is something that has happened in the past, is named in the past tense ("UserProfileFetched", "LikeSentToServer", "ServerFailedToHandleLike") and that can't be rejected by the subscribers, since you can't change the past (in that it differs from "commands" and "actions", which can be rejected by the handler or fail). We have a lot of intuitive knowledge about the events and the past (e.g. see this image https://twitter.com/abdullin/status/532464175671672832)
"Event creator" was accepted well in explanations as well, since "creator" feels like a "factory": just a helper method, which contains the bare minimum of logic to create events.
However, while explaining Flux in these terms, I always clarify that all original documentation on the subject refers to these items as "actions" and "action creators".
Best regards, Rinat
Rinat Abdullin | Writer at Abdullin.com http://abdullin.com
On Tue, Feb 24, 2015 at 10:04 PM, Bill Fisher [email protected] wrote:
Yeah, the name is probably a little clumsy. There's a lot of information out in the world now about action creators, so I doubt we want to create more confusion by changing the name now.
The history here is that we used to call the FooActionCreators module just simply FooActions, but this led to some confusion -- the methods were seen as the action instead of the object they create and pass to the dispatcher. In the summer of 2014 Jing Chen and I were putting together a presentation for ForwardJS http://facebook.github.io/flux/docs/videos.html#react-and-flux-building-applications-with-a-unidirectional-data-flow-forward-js-2014 and we wanted to dispel this confusion. We came up with ActionCreator a day or two before the conference. Now we're a bit stuck with it.
I'll think about it, though. Thanks for bringing it up.
I think Actor or Intent is a fine name for these methods, and I encourage you to do what you think is best for your teams. There are connotations to both that I might quibble with, however.
Actor tends to be something with agency, which these methods do not really have.
Intent leans toward thinking of the methods like setters, and this is an easy trap to fall into. The actions are reporting on something that happened in the real world -- the user clicked, the server responded, etc -- and the Flux stores need to respond to this real world change. Intent implies that the server "intends" for something to happen in the client side application, which is not really true -- it's the store that needs listen to actions and respond. The actions are more like a newspaper, reporting on the real world. Thinking more in these terms, I've switched to naming all my action types in the past tense.
See also this conversation I had with @abdullin https://github.com/abdullin, who is the person who first emphasized this "past" quality of actions. https://gist.github.com/abdullin/5953ab4f5eae0a7fc8f9
— Reply to this email directly or view it on GitHub https://github.com/facebook/flux/issues/165#issuecomment-75797532.
Thanks for the lively discussion. I'm learning a lot from you guys. I agree with @fisherwebdev that neither Intent nor Actor fully captures the purpose of ActionCreators. Using the past tense in the action name is a fantastic suggestion. Sometimes I get asked if it's possible to prevent an action by returning false, which indicates the confusion that an ActionCreator might be like an ordinary event handler, and this naming convention might prevent that mistake.
Call them simply actions. When a component needs to perform a particular task it executes the relevant action. That "action" code could perform a server side call, or two, and dispatch out events (in past tense) informing the rest of the system of what just occurred. So it comes down to just two terms then; actions that could be performed, and events that occur.
One of the reasons we chose the name Intents is that conceptually an actor has the intent to do something, but the actual behavior of the flux system as a result of that intent is unknown by the actor. For example, you have the intent to fetch new ToDo data from the server.
// pseudocode
ToDoIntents.refreshFromServer = function() { // asynchronously tries to fetch the data, meanwhile...
dispatch Constants.TODO_REFRESH_ATTEMPTED // past tense
// later, on response from server...
dispatch Constants.TODO_REFRESH_SUCCEEDED // or FAILED, also past tense
}
Types of actor could include humans, time, network conditions, or external systems. An actor could be a human (clicking a refresh button, manually log out), or it could be time (refresh every n mins, session expired).
p.s. @fisherwebdev thanks for the detailed discussion!
p.p.s also using past tense for the action names is a great idea. Again we made a little naming tweak here and called the actions messages. Because action implied intent to do something but really it is a message that something already happened.
Thank you for reporting this issue and appreciate your patience. We've notified the core team for an update on this issue. We're looking for a response within the next 30 days or the issue may be closed.
I don't think we will be changing from the name Action Creators anytime soon. Even if it isn't the perfect name.