Guest User

Untitled

a guest
Nov 13th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. import { connect } from 'react-redux'
  2. import { actionC } from '../actions';
  3. import React from 'react';
  4.  
  5. export default function (ComposedComponent, _mapStatetoProps, _mapDispatchToProps) {
  6. class SuperComponent extends React.PureComponent {
  7. componentWillMount(){
  8. this.props.registeredDispatchers.forEach((dispatcherName) => {
  9. this.props[dispatcherName]();
  10. });
  11. }
  12.  
  13. render () {
  14. return <ComposedComponent {...this.props} {...this.boundActionCreators} />
  15. }
  16. }
  17.  
  18. function mapStateToProps(state) {
  19. const {stateC} = state;
  20. const reducedState = _mapStatetoProps(state);
  21. return Object.assign({}, reducedState, {stateC});
  22. }
  23.  
  24. const mapDispatchToProps = (dispatch) => {
  25. var functionsToBeDispatched = {
  26. ..._mapDispatchToProps(dispatch),
  27. actionC(){
  28. dispatch(actionC());
  29. }
  30. };
  31.  
  32. functionsToBeDispatched.registeredDispatchers = Object.keys(functionsToBeDispatched)
  33. return functionsToBeDispatched;
  34. };
  35.  
  36. return connect(mapStateToProps, mapDispatchToProps)(SuperComponent);
  37. }
Add Comment
Please, Sign In to add comment