官术网_书友最值得收藏!

Action – capture the intent

An action is something as simple as an intent with accompanying data, that is, a message. How does an action come about though? An action comes about when a user interacts with a UI. The user may select a specific item in a list or a press a button with the intention of submitting a form. Submitting the form should, in turn, lead to a product being created.

Let's look at two different actions:

  • Selecting an item in a list, here we are interested in saving the index of our selected item
  • Saving a todo to a todo list

An action is represented by an object. The object has two properties of interest:

  • The type: This is a unique string that tells us the intention of the action, for example, SELECT_ITEM
  • The data: This is the data we mean to persist, for example, the numerical index of a selected item

Given our first example action, a code representation of that action would look like the following:

{
type: 'SELECT_ITEM',
data: 3 // selected index
}

OK, so we have prepared our action, which we can also think of as a message. We want the message to be sent so that the selected item is highlighted in the UI. As this is a undirectional flow, we need to follow a charted course and pass our message over to the next party, which is the dispatcher.

主站蜘蛛池模板: 溆浦县| 定西市| 城市| 芦溪县| 广灵县| 泾源县| 遂川县| 镇安县| 田东县| 霍山县| 安宁市| 姜堰市| 双峰县| 正镶白旗| 色达县| 阜平县| 清水县| 虎林市| 剑川县| 崇礼县| 武夷山市| 鹤庆县| 曲水县| 紫云| 莫力| 精河县| 隆尧县| 临邑县| 西华县| 花莲县| 渭南市| 横山县| 隆子县| 禄丰县| 库尔勒市| 五家渠市| 大渡口区| 武鸣县| 涟源市| 古田县| 巩留县|