- Redux Quick Start Guide
- James Lee Tao Wei Suresh Kumar Mukhiya
- 251字
- 2021-07-02 12:40:30
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:
- Adding a user to the hospital management system
- Deleting a user from the hospital management system
- Updating a user
- 算法零基礎一本通(Python版)
- C# Programming Cookbook
- 跟老齊學Python:輕松入門
- JavaScript入門經典
- 大模型RAG實戰:RAG原理、應用與系統構建
- 全棧自動化測試實戰:基于TestNG、HttpClient、Selenium和Appium
- Working with Odoo
- PHP+MySQL+Dreamweaver動態網站開發從入門到精通(第3版)
- Android應用開發深入學習實錄
- R Data Science Essentials
- Everyday Data Structures
- Python Machine Learning Blueprints:Intuitive data projects you can relate to
- Python Deep Learning
- Java EE項目應用開發
- AngularJS UI Development