Actions

Actions define the internal API of your application. They capture the ways in which anything might interact with your application. They are simple objects that have a “type” field and some data.

Actions should be semantic and descriptive of the action taking place. They should not describe implementation details of that action. Use “delete-user” rather than breaking it up into “delete-user-id”, “clear-user-data”, “refresh-credentials” (or however the process works). Remember that all stores will receive the action and can know they need to clear the data or refresh credentials by handling the same “delete-user” action.

Examples:

When a user clicks “delete” on a completed todo a single “delete-todo” action is dispatched:

{

type: ‘delete-todo’,

todoID: ‘1234’,

}

Action Creators are collections of methods that are called within views (or anywhere else for that matter) to send actions to the Dispatcher. Actions are the actual payloads that are delivered via the dispatcher.

The way Facebook uses them, action type constants are used to define what action should take place, and are sent along with action data. Inside of registered callbacks, these actions can now be handled according to their action type, and methods can be called with action data as the arguments.

Share this post
[social_warfare]
Store
Views

Get industry recognized certification – Contact us

keyboard_arrow_up