Skip to content

redux入门之三大原则 #8

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

Open
sunyongjian opened this issue Dec 11, 2016 · 0 comments
Open

redux入门之三大原则 #8

sunyongjian opened this issue Dec 11, 2016 · 0 comments
Labels

Comments

@sunyongjian
Copy link
Owner

三个概念

  • Store

  • Action

  • Reducer

三大准则

  • 单一数据源

    整个应用状态,都应该被存储在单一store的对象树中(object tree)。

  • State 是只读的

    唯一改变state的方法,就是发送(dispatch)一个动作(Action),action 是一个用于描述已发生事件的普通对象

  • 使用纯函数去修改状态

    为了描述action 如何改变 state tree,需要写reducers

    reducer 只是一些纯函数。。(pure function)可被看成是一个状态机,在任何时候,只要有相同的输入,就会得到相同的输出

    function add1(a,b) {
        return a + b
    }
    var a = 0;
    function add2(b) {
        return a = a + b
    }
    add1(1,2)   add1(1,2) 
    
    add2(1)     add2(1)    
    

    This is an source code.

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