


Methods to migrate database to SQL Server using EF Core in .NET Core class library_Practical tips
This article mainly introduces the summary of the Redux architecture used in ReactNative. The editor thinks it is quite good. Now I will share it with you and give it a reference. Friends who are interested in .NET should follow the editor to take a look.
This article introduces a summary of the Redux architecture used in ReactNative and shares it with everyone. The details are as follows:
I have been using Redux for some time. in conclusion.
Why use Redux?
Background:
RN’s state (variable, subcomponents are invisible) and The design of props (immutable, visible to sub-components), when faced with large-scale projects, can easily cause state confusion due to inadvertent modification of state, and component rendering errors
RN uses Virtual DOM, which does not Target binding->Action is required to modify the UI properties. As long as the state changes, the component in the new state is rendered, and the data is transmitted in one direction, while the MVC design pattern has a two-way data flow.
RN is not easy to test. Redux provides a very convenient mock testing method.
Redux development
Development environment
Install Redux: 'npm install –save redux'
Install React Native and Redux binding libraries: npm install –save react-redux
Install Redux Thunk asynchronous Action middleware: npm install –save redux-thunk
Three principles
Single data source
The entire application's state is stored in an object tree, which exists in a unique store. The state in the store is bound to the component
State is read-only
The only way to change the state is to trigger the action. action is an ordinary JS object containing a type attribute, which can represent events as constants.
Use pure functions to perform modifications
Write reducers to describe how the corresponding action modifies state. Generally, you can use switch(action.type) to handle it without side effects
Use
react-redux provides connect and Provider.
1. Provider is the top-level distribution point, and its attribute is Store, which distributes State to all connected components
2. connect: accepts two parameters: one is mapStateToProps or mapDispatchToProps, one is the component itself to be bound.
Store
Store is the object that connects Reducer and action. Store has the following responsibilities:
Maintain the state of the application – similar to a database, storing all the state of the application.
Provide getState() method. Obtain all current states;
Provides the dispatch(action) method to update the state, which is equivalent to storing it in the database and storing the action to change the state.
Register the listener through subscribe(listener).
Store is essentially an object that saves the entire application's State in the form of a tree. and provides some methods. For example getState() and dispatch().
Redux application has only one Store.
Store is created through the createStore method, based on the initial State of the root Reducer of the entire application.
The code is as follows:
##
import { createStore, applyMiddleware } from 'redux'; import thunk from 'redux-thunk';//异步 import reducers from './reducers'; const Store = applyMiddleware(thunk)(createStore)(reducers); export default Store;
Reducers
Action only describes the fact that something happened, and does not specify how the application updates state. This is what the reducer does. The essence of Reducer is a function, and it is a pure function. There are no side effects. Simply put, the Reducer is only responsible for doing one thing, which is to modify the state in the Store based on the received action and state:##
import { combineReducers } from 'redux'; const newState = (state = {}, action = {}) => { switch (action.type) { case ActionTypes.CSTATE: return { ...state, ...action.state }; case '_DPDATACHANGE_': return {...state, ...action.dpState}; default: return state; } }; //Reducer 合并 export default combineReducers({ newState, });
Note: The new state is returned, if you need to keep it For some old state values, use...state (the object expansion syntax of ES7 will shallowly copy the corresponding properties of the object, which is equivalent to Object.assign({}, state, newState)). If you merge state, you will only merge one layer. , complex states need to be merged manually.
Action is an ordinary JS object, including at least one type attribute representing the event, and other attributes can be used to pass data. In practice, a function is defined for a process. The process can include network requests and finally return Action. This function is called Action Creator.
Code: Store can dispatch this Action. The type of action represents the identifier, and state is the data it carries.
export const newState = state => { Store.dispatch({ type: ActionTypes.CSTATE, state, }); };
When the action is triggered, the data is restored according to its reducer key. Then you only need to distribute the action when the application starts, which can be easily abstracted into a configurable extension service. In fact, the third-party library redux-persist has already done all this for us.
The code in Action can be as follows:
export const getStorage = async (key) => { const d = await AsyncStorage.getItem(key); return JSON.parse(d); }; export const setStorage = (key, value) => { AsyncStorage.setItem(key, JSON.stringify(value)); };
Pass - Provides getState() method. Get all current state
通过connect,绑定需要的state以及Action Creator到你的组件的props上,这样组件就可以通过props来调用Action Creator,或者根据不同props来render()不同的组件。
代码:
mapStateToProps({ newState }) { const value = newState[name];//name: newState.name return { name, }; },
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持PHP中文网。
相关推荐:
JavaScript技巧中关于react-redux中connect()方法详细解析
The above is the detailed content of Methods to migrate database to SQL Server using EF Core in .NET Core class library_Practical tips. For more information, please follow other related articles on the PHP Chinese website!

C# and .NET runtime work closely together to empower developers to efficient, powerful and cross-platform development capabilities. 1) C# is a type-safe and object-oriented programming language designed to integrate seamlessly with the .NET framework. 2) The .NET runtime manages the execution of C# code, provides garbage collection, type safety and other services, and ensures efficient and cross-platform operation.

To start C#.NET development, you need to: 1. Understand the basic knowledge of C# and the core concepts of the .NET framework; 2. Master the basic concepts of variables, data types, control structures, functions and classes; 3. Learn advanced features of C#, such as LINQ and asynchronous programming; 4. Be familiar with debugging techniques and performance optimization methods for common errors. With these steps, you can gradually penetrate the world of C#.NET and write efficient applications.

The relationship between C# and .NET is inseparable, but they are not the same thing. C# is a programming language, while .NET is a development platform. C# is used to write code, compile into .NET's intermediate language (IL), and executed by the .NET runtime (CLR).

C#.NET is still important because it provides powerful tools and libraries that support multiple application development. 1) C# combines .NET framework to make development efficient and convenient. 2) C#'s type safety and garbage collection mechanism enhance its advantages. 3) .NET provides a cross-platform running environment and rich APIs, improving development flexibility.

C#.NETisversatileforbothwebanddesktopdevelopment.1)Forweb,useASP.NETfordynamicapplications.2)Fordesktop,employWindowsFormsorWPFforrichinterfaces.3)UseXamarinforcross-platformdevelopment,enablingcodesharingacrossWindows,macOS,Linux,andmobiledevices.

C# and .NET adapt to the needs of emerging technologies through continuous updates and optimizations. 1) C# 9.0 and .NET5 introduce record type and performance optimization. 2) .NETCore enhances cloud native and containerized support. 3) ASP.NETCore integrates with modern web technologies. 4) ML.NET supports machine learning and artificial intelligence. 5) Asynchronous programming and best practices improve performance.

C#.NETissuitableforenterprise-levelapplicationswithintheMicrosoftecosystemduetoitsstrongtyping,richlibraries,androbustperformance.However,itmaynotbeidealforcross-platformdevelopmentorwhenrawspeediscritical,wherelanguageslikeRustorGomightbepreferable.

The programming process of C# in .NET includes the following steps: 1) writing C# code, 2) compiling into an intermediate language (IL), and 3) executing by the .NET runtime (CLR). The advantages of C# in .NET are its modern syntax, powerful type system and tight integration with the .NET framework, suitable for various development scenarios from desktop applications to web services.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 English version
Recommended: Win version, supports code prompts!

Dreamweaver Mac version
Visual web development tools

Zend Studio 13.0.1
Powerful PHP integrated development environment

SublimeText3 Mac version
God-level code editing software (SublimeText3)

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function