redux

Redux can I use one action type in separate reducers?

旧城冷巷雨未停 提交于 2020-03-17 03:52:48
问题 I have a situation in my Redux application where I currently have 3 separate reducers that handle the fetching of data from an api. An example of one of my reducers would be: const INITIAL_STATE = { data: [], loading: false, error: '' }; export default (state = INITIAL_STATE, action) => { switch (action.type) { case GET_ALL_ORDERS_START: return { ...state, loading: true }; case GET_ALL_ORDERS_SUCCESS: return { ...state, allOrders: action.payload, loading: false }; case GET_ALL_ORDERS_FAIL:

React hooks: dispatch action from useEffect

て烟熏妆下的殇ゞ 提交于 2020-03-12 19:00:20
问题 My folder structure: |--App |--Components |--PageA.js |--PageB.js |--PageC.js |--common-effects |--useFetching.js I am refactoring my code to fetch data from API, using react hooks. I want to dispatch an action from useEffect in useFetching.js that is intercepted by saga middleware. The action should be dispatched only when the components( PageA , PageB , PageC ) mount. I am using redux , react-redux and redux-saga . PageA.js : function(props) { useFetching(actionParams) //....// } Similar

阮一峰的redux教学

百般思念 提交于 2020-03-12 18:52:56
mobx后面再去了解。 http://www.ruanyifeng.com/blog/2016/09/redux_tutorial_part_one_basic_usages.html React 只是 DOM 的一个抽象层,并不是 Web 应用的完整解决方案 ,所以要配合React-redux (redux的一个react版本) 和redux相似的技术库:早期的 flux, Immutable, Rxjs,vue版的 vuex等。 你的应用有以下场景,可以考虑使用 Redux。 某个组件的状态,需要共享 某个状态需要在任何地方都可以拿到 一个组件需要改变全局状态 一个组件需要改变另一个组件的状态 发生上面情况时,如果不使用 Redux 或者其他 状态管理工具 ,不按照一定规律处理状态的读写,代码很快就会变成一团乱麻。你需要一种机制,可以 在同一个地方查询状态、改变状态、传播状态的变化 。 总之,不要把 Redux 当作万灵丹,如果你的应用没那么复杂,就没必要用它。另一方面,Redux 只是 Web 架构的一种解决方案,也可以选择其他方案。 Redux 的设计思想很简单 ,就两句话。 (1)Web 应用是一个状态机,视图与状态是一一对应的。 (2)所有的状态,保存在一个对象里面。 基本概念 store state Action Store 就是保存数据的地方,你可以把它看成一个容器

Store not updated in redux?

99封情书 提交于 2020-03-12 05:45:50
问题 In the "Favorite List" reducer I have two helper function "Add/Remove" item from the array the Add work well but Remove it does not update the store in the actual time, because I have a checker in my UI that checks if this song_id in the array or not and bassed on it I update the heart icon BUT it does not work well when I dispatch the remove Action, In Other Words " Not Re-render the component "!. Action File import {ADD_TO_FAVORITE, REMOVE_FROM_FAVORITE} from './types'; export const

react-redux使用入门

泪湿孤枕 提交于 2020-03-11 09:38:04
安装 npm install --save redux npm install --save react-redux npm install redux-thunk npm install --save-dev redux-devtools 上面的三个命令分别安装了redux库、React绑定库、redux-thunk中间件和开发者工具 建结构 mkdir actions mkdir reducers mkdir components mkdir containers mkdir store 上面的命令在根目录下新建了五个文件夹 actions 存放了所有的动作,在组件中通过diapatch来触发action的方法 reducers 存放了所有更新state的方法,action方法触发reducer来更新state components 存放了所有的组件 containers 存放了容器组件,通过容器我们把state的值绑定到组件props上,把action创建函数绑定到props上 store 存放用于注册store的配置文件 基本使用 一个简单的例子,实现一个拉取豆瓣top250电影的列表 新建项目模板文件 touch index.html 在根目录下新建index.html文件作为项目的模板文件,内容如下 <!DOCTYPE html> <html> <head> <meta

redux源码阅读(进行中)

ε祈祈猫儿з 提交于 2020-03-09 07:00:44
入口:index.js(目录)重点标红 import createStore from './createStore' import combineReducers from './combineReducers' import bindActionCreators from './bindActionCreators' import applyMiddleware from './applyMiddleware' import compose from './compose' import warning from './utils/warning' import __DO_NOT_USE__ActionTypes from './utils/actionTypes' // types// store export {CombinedState, PreloadedState, Dispatch, Unsubscribe, Observable, Observer, Store, StoreCreator, StoreEnhancer, StoreEnhancerStoreCreator,ExtendState} from './types/store' // reducers export {Reducer,ReducerFromReducersMapObject

Rudex的使用方法与总结

江枫思渺然 提交于 2020-03-07 10:42:43
Rudex的使用方法与总结 Redux是什么 Redux是一个流行的JavaScript框架,为应用程序提供一个可预测的状态容器(即数据状态管理框架)。Redux基于简化版本的Flux框架,Flux是Facebook开发的一个框架。在标准的MVC框架中,数据可以在UI组件和存储之间双向流动,而Redux严格限制了数据只能在一个方向上流动。 Redux的工作原理 Redux的使用步骤 环境准备 安装redux cnpm install - D redux 文件准备:在src目录下新建store文件夹,用来存放所有和redux有关的文件。 创建图书记录本(Reducer) 在store文件夹中创建reducer.js文件,用来存储数据。 在reducer.js中创建需要使用的初始state数据,并对外暴露一个返回state的函数,用来处理任务并返回处理结果。 const defaultState = { defaultValue : "要借什么书" , } ; export default ( state = defaultState , action ) => { return state ; } 招聘图书管理员(store) 在store文件夹中创建index.js文件,用于实现三方通讯(记录本、用户、展示大屏)。 在index.js中引入redux: import {

React之Redux

﹥>﹥吖頭↗ 提交于 2020-03-07 06:39:28
  本文简单的说下redux。   首先这有张网页,里面有文字和内容。 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>ReactDemo</title> </head> <body> <div id="title"></div> <div id="content"></div> <div id="root"></div> </body> </html>   现在让这个网页通过状态来显示标题和内容。 let state = { title:{ color:'red', text:'标题' }, content:{ color:'blue', text:'内容' } } function renderTitle(){ let title = document.querySelector('#title'); title.style.background = state.title.color; title.innerHTML = state

web前后端 技术栈

大城市里の小女人 提交于 2020-03-05 15:16:31
1、 Jenkins 是一个开源软件项目,旨在提供一个开放易用的软件平台,使软件的持续集成变成可能。 2、 Vagrant 是一个基于Ruby的工具,用于创建和部署虚拟化开发环境。它 使用Oracle的开源 VirtualBox 虚拟化系统,使用 Chef创建自动化虚拟环境。 3、 Apache MINA 是一个网络应用程序框架,用来帮助用户简单地开发高性能和高可扩展性的网络应用程序。它提供了一个通过 Java NIO在不同的传输例如TCP/IP和UDP/IP上抽象的 事件驱动 的异步API。 4、 Gollum 是 Git 上面 wiki 系统的构造工具,简单实用。Gollum wikis 是简单的 Git 库,遵循特定的格式。Gollum 上面允许使用多种格式,有多种编辑的方式。 5、 React 是一个 Facebook 和 Instagram 用来创建用户界面的 JavaScript 库。很人多认为 React 是 MVC 中的 V (视图)。 6、 Redux 是应用状态管理服务。虽然本身受到了 Flux 很深的影响,但是其核心概念却非常简单,就是 Map/Reduce 中的 Reduce。 7、 Webpack 是一款专为Web开发设计的包管理器。它能够很好地管理、打包Web开发中所用到的HTML、Javascript、CSS以及各种静态文件(图片、字体等)

深入学习和理解 Redux

浪子不回头ぞ 提交于 2020-03-05 09:42:51
本文首发于 vivo互联网技术 微信公众号 链接: https://mp.weixin.qq.com/s/jhgQXKp4srsl9_VYMTZXjQ 作者:曾超 Redux官网上是这样描述Redux,Redux is a predictable state container for JavaScript apps.(Redux是JavaScript状态容器,提供可预测性的状态管理)。 目前Redux GitHub有5w多star,足以说明 Redux 受欢迎的程度。 一、Why Redux 在说为什么用 Redux 之前,让我们先聊聊组件通信有哪些方式。常见的组件通信方式有以下几种: 父子组件:props、state/callback回调来进行通信 单页面应用:路由传值 全局事件比如EventEmitter监听回调传值 react中跨层级组件数据传递Context(上下文) 在小型、不太复杂的应用中,一般用以上几种组件通信方式基本就足够了。 但随着应用逐渐复杂,数据状态过多(比如服务端响应数据、浏览器缓存数据、UI状态值等)以及状态可能会经常发生变化的情况下,使用以上组件通信方式会很复杂、繁琐以及很难定位、调试相关问题。 因此状态管理框架(如 Vuex、MobX、Redux等)就显得十分必要了,而 Redux 就是其中使用最广、生态最完善的。 二、Redux Data flow