当前位置:网站首页>[Shanda conference] project introduces Redux
[Shanda conference] project introduces Redux
2022-06-22 16:03:00 【What does Xiao Li Mao eat today】
List of articles
Preface
React Using a one-way data flow , In order to realize data flow, it is shared among different components , I introduced... For the project Redux Perform global data state management .
Installation dependency
Installation is required first redux Core dependence :
yarn add @reduxjs/toolkit
Define activities
We are src/Utils Create a new folder under Store, Create a new file actions.js .
/** * action type */
export const UPDATE_AVAILABLE_VIDEO_DEVICES = 'UPDATE_AVAILABLE_VIDEO_DEVICES'
export const UPDATE_AVAILABLE_AUDIO_DEVICES = 'UPDATE_AVAILABLE_AUDIO_DEVICES'
export const EXCHANGE_VIDEO_DEVICE = 'EXCHANGE_VIDEO_DEVICE'
export const EXCHANGE_AUDIO_DEVICE = 'EXCHANGE_AUDIO_DEVICE'
/** * Other constants */
export const DEVICE_TYPE = {
VIDEO_DEVICE: 'video',
AUDIO_DEVICE: 'audio'
}
/** * action Activities */
export function updateAvailableDevices(deviceType, devices) {
switch (deviceType) {
case DEVICE_TYPE.VIDEO_DEVICE:
return {
type: UPDATE_AVAILABLE_VIDEO_DEVICES, devices }
case DEVICE_TYPE.AUDIO_DEVICE:
return {
type: UPDATE_AVAILABLE_AUDIO_DEVICES, devices }
default:
return null
}
}
export function exchangeMediaDevice(deviceType, deviceInfo) {
switch (deviceType) {
case DEVICE_TYPE.VIDEO_DEVICE:
return {
type: EXCHANGE_VIDEO_DEVICE, deviceInfo }
case DEVICE_TYPE.AUDIO_DEVICE:
return {
type: EXCHANGE_AUDIO_DEVICE, deviceInfo }
default:
return null
}
}
Define distributor
stay Store Under the folder , establish reducers.js.
import {
combineReducers } from '@reduxjs/toolkit';
import {
UPDATE_AVAILABLE_VIDEO_DEVICES,
UPDATE_AVAILABLE_AUDIO_DEVICES,
EXCHANGE_AUDIO_DEVICE,
EXCHANGE_VIDEO_DEVICE,
} from './actions'
function updateAvailableVideoDevices(state = [], action) {
switch (action.type) {
case UPDATE_AVAILABLE_VIDEO_DEVICES:
action.devices.push()
return action.devices
default:
return state
}
}
function updateAvailableAudioDevices(state = [], action) {
switch (action.type) {
case UPDATE_AVAILABLE_AUDIO_DEVICES:
return action.devices
default:
return state
}
}
function exchangeVideoDevice(state = null, action) {
switch (action.type) {
case EXCHANGE_VIDEO_DEVICE:
localStorage.setItem('usingVideoDevice', action.deviceInfo.key)
return action.deviceInfo
default:
return state
}
}
function exchangeAudioDevice(state = null, action) {
switch (action.type) {
case EXCHANGE_AUDIO_DEVICE:
localStorage.setItem('usingAudioDevice', action.deviceInfo.key)
return action.deviceInfo
default:
return state
}
}
const reducers = combineReducers({
availableVideoDevices: updateAvailableVideoDevices,
availableAudioDevices: updateAvailableAudioDevices,
usingVideoDevice: exchangeVideoDevice,
usingAudioDevice: exchangeAudioDevice
})
export default reducers;
export Redux
stay Store Under the folder , establish store.js.
import {
configureStore } from '@reduxjs/toolkit';
import reducers from './reducers';
const store = configureStore({
reducer: reducers,
});
export default store;
边栏推荐
- 标准化、最值归一化、均值归一化应用场景的进阶思考
- 静态断言 static_assert
- ORB_VI思想框架
- (pytorch advanced path 2) word embedding and position embedding
- Promoting compatibility and adaptation, enabling coordinated development of gbase may adaptation Express
- Applet development - Custom expiration cache
- 数值类型和字符串之间的转换
- [译文] 弥合开源数据库和数据库业务之间的鸿沟
- C language learning -18-makefile file writing examples and how to generate and call dynamic libraries
- 程序替换函数
猜你喜欢

Gbase "library" special training of innovation and application Committee of Beijing fintech Industry Alliance

【newman】postman生成漂亮的测试报告

Pymssql Module User Guide

C语言学习-17-函数作为参数传入函数
![[译文] 弥合开源数据库和数据库业务之间的鸿沟](/img/e5/f89a8f3e2e9034f557ea3e76f37f81.jpg)
[译文] 弥合开源数据库和数据库业务之间的鸿沟

pymssql模块使用指南

快速玩转CI/CD图形化编排

Binary search (integer binary)

推进兼容适配,使能协同发展 GBase 5月适配速递

Uni develops wechat applet to customize automatic camera detection (portrait + ID card)
随机推荐
【山大会议】私人聊天频道 WebRTC 工具类
Simulation of vector
HMS Core新闻行业解决方案:让技术加上人文的温度
Scala language learning-05-a comparison of the efficiency of recursion and tail recursion
Development status of full color LED display
GBASE现身说 “库” 北京金融科技产业联盟创新应用专委会专题培训
Application of mongodb in Tencent retail premium code
校企联合在路上!华为云GaussDB又来高校啦
webDriver以及Selenium使用总结
Jenkins 通过检查代码提交自动触发编译
小程序开发----自定义有效期缓存
Program substitution function
[leetcode] 9. Palindromes
The MIHA tour club in June is hot! 500+ posts, more than HC, just this summer (with internal promotion method)
HMS core news industry solution: let technology add humanistic temperature
华为机器学习服务银行卡识别功能,一键实现银行卡识别与绑定
Scala language learning-06-differences between name passing parameters, value passing parameters and function passing parameters
Promoting compatibility and adaptation, enabling coordinated development of gbase may adaptation Express
Navicat Premium 连接Oracle 数据库(图文教程)
Simulation Implementation of string