1. function bindActionCreator(actionCreator, dispatch) {
    2. return (...args) => {
    3. dispatch(actionCreator.apply(this, args)) // 同步的方法
    4. }
    5. }
    6. function bindActionCreators(actionCreators, dispatch) {
    7. if(typeof actionCreators === 'function') {
    8. return bindActionCreator(actionCreators, dispatch)
    9. }
    10. if(Object.prototype.toString.call(actionCreators) !== "[object Object]") {
    11. throw new Error('actionCreators 必须是对象格式')
    12. }
    13. const bondActionCreators = {}
    14. const actionKeys = Object.keys(actionCreators)
    15. // 如果是对象就迭代绑定这个对象
    16. for(const key of actionKeys) {
    17. const value = actionCreators[key]
    18. bondActionCreators[key] = bindActionCreator(value, dispatch)
    19. }
    20. return bondActionCreators
    21. }
    22. export default bindActionCreators