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

Actions

Actions are simply JavaScript objects describing the changes in the state of the application. To be specific, they are payloads of information that transfer data from our application to the state. Does this not make sense to you? No problem. Let's look at an example use case. Suppose that we need to add a doctor's information to our hospital management system:

const ADD_NEW_DOCTOR_REQUEST = "ADD_NEW_DOCTOR_REQUEST"

It isn't rocket science, right? It's just a simple, constant ADD_DOCTOR_REQUEST. Now, let's create an object:

{
type: ADD_NEW_DOCTOR_REQUEST,
data: {
name: ‘Dr. Yoshmi Mukhiya’,
age: 22,
department: ‘Mental Health’,
telecom: ‘99999999’
}
}

This is a simple, plain JavaScript object, and it is referred to as an action. An action must have the type property that defines the type of action to be performed. In this use case, the action is adding an action. The type is basically a string constant. In any web application, there are a multitude of actions required. So, the general (and most common) trend is to separate these actions into separate files and import them into the required place.

Now, let's assume that we need to delete a doctor's record from our app. We should be able to create an action object easily, as follows:

{
type: 'DELETE_DOCTOR_REQUEST',
identifier: 201,
}

Now, go ahead and create the actions for the following:

  1. Adding a user to the hospital management system
  2. Deleting a user from the hospital management system
  3. Updating a user
主站蜘蛛池模板: 新余市| 军事| 洪泽县| 平度市| 定日县| 砀山县| 渭源县| 密山市| 胶南市| 石渠县| 岚皋县| 和静县| 西贡区| 天等县| 嘉黎县| 临潭县| 塔城市| 肥东县| 方城县| 上饶县| 桐城市| 繁峙县| 龙陵县| 东平县| 昌平区| 永胜县| 长宁县| 长沙县| 玉龙| 天等县| 汤原县| 安平县| 扶绥县| 班玛县| 镇江市| 老河口市| 永寿县| 镶黄旗| 赣州市| 田阳县| 皋兰县|