freeCodeCamp/curriculum/challenges/chinese/03-front-end-libraries/redux/define-a-redux-action.chine...

1.8 KiB
Raw Blame History

id title challengeType isRequired videoUrl localeTitle
5a24c314108439a4d403614d Define a Redux Action 6 false 定义Redux动作

Description

由于Redux是一个状态管理框架因此更新状态是其核心任务之一。在Redux中所有状态更新都由调度操作触发。操作只是一个JavaScript对象其中包含有关已发生的操作事件的信息。 Redux存储接收这些操作对象然后相应地更新其状态。有时Redux操作也会携带一些数据。例如操作在用户登录后携带用户名。虽然数据是可选的但操作必须带有type属性该属性指定发生的操作的“类型”。将Redux操作视为信使将有关应用程序中发生的事件的信息提供给Redux商店。然后商店根据发生的操作开展更新状态的业务。

Instructions

编写Redux操作就像声明具有type属性的对象一样简单。声明一个对象action并为其设置一个属性type设置为字符串'LOGIN'

Tests

tests:
  - text: 应该存在一个操作对象。
    testString: 'assert((function() { return typeof action === "object" })(), "An action object should exist.");'
  - text: 该操作应具有值为<code>LOGIN</code>的键属性类型。
    testString: 'assert((function() { return action.type === "LOGIN" })(), "The action should have a key property type with value <code>LOGIN</code>.");'

Challenge Seed

// Define an action here:

Solution

// solution required