-
Notifications
You must be signed in to change notification settings - Fork 11
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 源码分析 #23
Comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
redux 源码分析
原文链接
简介
三大原则
对比 mobx
而 mobx 一般对于一个页面或页面级别的组件创建 store,然后在一个总文件中导入,作为一个大对象导出给 context。
而 mobx
@observable state
可以随意改变,甚至逻辑分散在视图 view 层,例如onClick={() => (state.status = 1)}
。虽然官方建议把逻辑封装在 action 中,例如
@action updata() {}
,但不是一种强约束。state.xx = 1; return state
,应该是return { ...state, xx: 1}
。而鉴于 mobx 的机制, mobx 更别说了。
所以常说,mobx 常用中小型应用,redux 更适合大型应用。
概览
使用
例子都是摘录来的,不想看的可以跳过。
深入 redux
createStore
到此最重要的 createStore 函数就实现完毕。接下来分析两个辅助函数 bindActionCreators,combineReducers,最后分析实现中间件功能的 compose、applyMiddleware。
bindActionCreators
combineReducers
compose
applyMiddleware
thunk 中间件
applyMiddleware(a, b)
,a 中的 next 就是 b 中返回的 action => {} 函数,b 中的 next 就是 store.dispatch。这样就串起来了。总结
完。
The text was updated successfully, but these errors were encountered: