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 之 Store 知识点 #2

Open
oliver1204 opened this issue Feb 7, 2018 · 0 comments
Open

redux 之 Store 知识点 #2

oliver1204 opened this issue Feb 7, 2018 · 0 comments

Comments

@oliver1204
Copy link
Owner

oliver1204 commented Feb 7, 2018

1. 什么是store

store是用来维持应用所有state的的一个对象,也可以说是一个方法的集合.

2. 创建store

要创建store只需要将根reducer作为参数传递给createStore函数。

var store = createStore(todoApp);

3.store的方法

  1. getState:获取到当前的state
  2. dispatch: 他就是我们反复强调的唯一的能改变state的那个函数。
  3. subscribe: 添加一个变化监听器,当dispatch action时他就会执行,我们可以在回调函数中使用getState函数,查看当前的state,在上一小节中我们还能看到,subscribe函数会返回一个解除监听的函数
  4. replaceReducer: 替换当前用来计算的reducer
@oliver1204 oliver1204 changed the title Store 知识点 redux 之 Store 知识点 Mar 1, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant