仓库(阅读版):https://github1s.com/reduxjs/redux

为什么要阅读Redux源码?

  • Redux实现简单,代码量小
  • 使用TypeScript编写
  • Facebook开源

    目录结构

    utils下工具函数,每个函数对应一个同名文件。

combineReducers

为什么要在 combination 函数中抛出 reducers 格式错误?

ps:在combineReducers中校验的。

reducer 不能返回 undefined
hasChanged存在的意义是?

bindActionCreators

将action包装成包含dispatch的函数包装dispatch,用途:在没有 dispatch 的组件内使用 action

createStore使用typeof判断值为 undefined的变量

参数验证使用 throw 中断执行,写在变量前面

subscribe

types

  1. interface ActionCreator<A, P extends any[] = any[]> { // ActionCreator<type> || ActionCreator<type, type>
  2. }