dvadva is a data flow solution based on redux and redux-saga. In order to simplify the development experience, dva also has built-in react-router and fetch, which can be transformed into a lightweight application framework. Using dva Define a model, a bit like redux-toolkit. Connect like redux's connect. start up. Find the corresponding reducer through the corresponding instructions and dispatch it. This is the basic operation of dva, which is relatively easy to use. Implementing DVAIdea: Encapsulate a function, create a store, collect reducers and states through models, and change the method name in reducers. First, the model. Because there are multiple models, we need to collect them. First, change the method name in rducer through namesapce. Then save it. Then it can be injected through Provider. Transform the reducer of the model and return the reducer accepted by redux. At this time, the state of the model will not change. It is just the initial state. What the component actually accepts is the state in redux. Initial implementation completed. Support asyncDva is integrated with redux-saga, so its usage is similar. When creating a model, you can create a saga middleware through effects. Then dispatch the corresponding action accomplish Idea: process the effects of each model, convert them into corresponding saga functions, use takeEvery to listen to each attribute name (such as asyncADD, converted to takeEvery('asyncADD', ()=>{}), etc.), then create a middleware through createSagaMiddleware provided by redux-saga, and use the run method to execute the saga functions converted from the effects in each model. Use getSagas to transform the effects of each model and store them in an array, then run them one by one through forEach. It can be seen that the effects of each model will be converted into function*(){} in getSaga, and then the effects of a single model will be traversed, and each attribute will be processed by *asyncADD(){}, as shown in the figure. A saga function is returned through getWatcher, and a child process is started through fork, which will not interfere with the operation of the main process. Each getWatcher returns a saga function (generator function), which monitors the current attribute (key) through takeEvery and executes the subsequent effects. Here we need to modify the Put method of redux-saga to make it do some prefixType logic separately. That's how it's done. It can run normally. Implementation of router There is no difference in using So the usage is similar to it. Note that asynchronous logic can only be written in effects. Reducer is synchronous and cannot continue to dispatch. accomplish:Based on connectd-react-router Remember how to use connectd-react-router? The first step is to create a router object. The second step is to use middleware. Pass the api to app._router as a parameter. That's it. When he sends a push, it will be intercepted and processed by the routing middleware and pushed to another page. This is the end of this article about react dva implementation. For more relevant react dva implementation content, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future! |
>>: Meta viewport makes the web page full screen display control on iPhone
The connection method in MySQL table is actually ...
The PHP base image used in this article is: php:7...
What does text-fill-color mean? Just from the lit...
byzhangxinxu from https://www.zhangxinxu.com/word...
Problem Description The MySQL startup error messa...
MongoDB Installation Choose to install using Yum ...
This article records the installation tutorial of...
I have nothing to do recently, so I tinker with C...
Related Articles: Website Design for User Experien...
Error scenario Use the mysql command in cmd to ad...
Table of contents Written in front Environment de...
MySQL tuning Explain tool detailed explanation an...
This article shares with you a graphic tutorial o...
Hello everyone, I am Liang Xu. When using Linux, ...
Before introducing the GROUP BY and HAVING clause...