Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redux #1

Open
ZoeyYoung opened this issue Dec 28, 2015 · 3 comments
Open

Redux #1

ZoeyYoung opened this issue Dec 28, 2015 · 3 comments
Labels

Comments

@ZoeyYoung
Copy link
Owner

ZoeyYoung commented Dec 28, 2015

Getting Started with Redux

(Redux作者录制,视频详解了 Todos 这个示例的由来,入门看这个很有帮助「如果能听懂英文」)

awesome-redux =》这里面的文章都能过一遍也就差不多了

文档&库

Redux中文文档
redux
react-redux
redux-thunk
redux-logger

Provider 的作用:传递Store

connect()的作用:生成容器组件

import { connect } from 'react-redux';

const mapStateToProps = (state) => ({
  xxx: stateXXX
})
const mapDispatchToProps = (dispatch) => {
  return {
    xxx: (xxx) => {
      dispatch(actionCreatorXXX)
    }
  };
}
const ContainerComponent = connect(mapStateToProps, mapDispatchToProps)(Component);

中间件

http://camsong.github.io/redux-in-chinese/docs/advanced/Middleware.html

It provides a third-party extension point between dispatching an action, and the moment it reaches the reducer.

基本形式

store => next => action => {
  ...
  let result = next(action)
  ...
  return result
}

工具

Chrome 插件 Redux DevTools

@ZoeyYoung ZoeyYoung changed the title XXX Redux学习资源 Dec 28, 2015
@ZoeyYoung
Copy link
Owner Author

@ZoeyYoung ZoeyYoung changed the title Redux学习资源 Redux Feb 4, 2016
@ZoeyYoung
Copy link
Owner Author

ZoeyYoung commented Mar 4, 2016

一个争论点,多个Action来完成一个State变更,还是一个Action完成所有变更

我是比较倾向于后面

1)多个Action会导致页面render多次
2)每个Action结束都不能保证数据的正确性,数据的正确性要依赖于容器是否根据state的变化调用相应的Action

场景

�一个Action的情况

添加数据成功后

1)表单数据可清空
2)数据列表更新

多个Action的情况

1)Action 1 添加数据成功
2)Action 2 重新加载数据列表(通过在容器中用某种方式判断balabala,如果容器没干这件事情,就是一个潜在的BUG)

Redux作者关于这个问题的回答:redux/issues/749、redux/issues/601

@ZoeyYoung
Copy link
Owner Author

遇到的问题

logout时需要进行数据清理

在项目中,用户登出的时候store和全部清理,如果所有reducer都监听登出事件有点傻,肯定有简单的方式

http://stackoverflow.com/questions/35622588/how-to-reset-the-state-of-a-redux-store

两种方式,其中比较简单的方式就是跳转到登录页时刷新,直接恢复至最原始�state

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant