mapDispatchToProps.js 933 B

123456789101112131415161718
  1. import bindActionCreators from '../utils/bindActionCreators';
  2. import { wrapMapToPropsConstant, wrapMapToPropsFunc } from './wrapMapToProps';
  3. export function whenMapDispatchToPropsIsFunction(mapDispatchToProps) {
  4. return typeof mapDispatchToProps === 'function' ? wrapMapToPropsFunc(mapDispatchToProps, 'mapDispatchToProps') : undefined;
  5. }
  6. export function whenMapDispatchToPropsIsMissing(mapDispatchToProps) {
  7. return !mapDispatchToProps ? wrapMapToPropsConstant(function (dispatch) {
  8. return {
  9. dispatch: dispatch
  10. };
  11. }) : undefined;
  12. }
  13. export function whenMapDispatchToPropsIsObject(mapDispatchToProps) {
  14. return mapDispatchToProps && typeof mapDispatchToProps === 'object' ? wrapMapToPropsConstant(function (dispatch) {
  15. return bindActionCreators(mapDispatchToProps, dispatch);
  16. }) : undefined;
  17. }
  18. export default [whenMapDispatchToPropsIsFunction, whenMapDispatchToPropsIsMissing, whenMapDispatchToPropsIsObject];