Skip to content

Commit

Permalink
Connect component - map dispatch to props multiline
Browse files Browse the repository at this point in the history
  • Loading branch information
yuriyyakym committed Jul 28, 2018
1 parent bf97c6d commit d6c3994
Show file tree
Hide file tree
Showing 28 changed files with 85 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ const mapStateToProps = (state) => ({
name: 'test'
});

const mapDispatchToProps = {};
const mapDispatchToProps = {

};

export const hoc = (Component) => connect(mapStateToProps, mapDispatchToProps)(Component);
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { connect } from 'react-redux';

const Component = () => (<span>123</span>);

const mapDispatchToProps = {};
const mapDispatchToProps = {

};

export default connect(null, mapDispatchToProps)(Component);
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { connect } from 'react-redux';

const ButtonComponent = () => (<span>123</span>);

const mapDispatchToProps = {};
const mapDispatchToProps = {

};

export const Button = withRouter(connect(null, mapDispatchToProps)(ButtonComponent));
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ const mapStateToProps = (state) => ({

});

const mapDispatchToProps = {};
const mapDispatchToProps = {

};

export const Button = connect(mapStateToProps, mapDispatchToProps)(ButtonComponent);
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { connect } from 'react-redux';

const Button = () => (<span>123</span>);

const mapDispatchToProps = {};
const mapDispatchToProps = {

};

export default connect(null, mapDispatchToProps)(Button);
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ export const withMyContext = (Component) => {

});

const mapDispatchToProps = {};
const mapDispatchToProps = {

};

return connect(mapStateToProps, mapDispatchToProps)(MyComponent);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ export const withMyContext = Component => {

});

const mapDispatchToProps = {};
const mapDispatchToProps = {

};

return connect(mapStateToProps, mapDispatchToProps)(InnerComponent);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ const mapStateToProps = (state) => ({

});

const mapDispatchToProps = {};
const mapDispatchToProps = {

};

export const Button = withRouter(connect(mapStateToProps, mapDispatchToProps)(ButtonComponent));
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ const mapStateToProps = (state) => ({

});

const mapDispatchToProps = {};
const mapDispatchToProps = {

};

export const Button = withRouter(connect(mapStateToProps, mapDispatchToProps)(ButtonComponent));
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ const mapStateToProps = (state) => ({

});

const mapDispatchToProps = {};
const mapDispatchToProps = {

};

export const Button = connect(mapStateToProps, mapDispatchToProps)(withRouter(ButtonComponent));
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const mapState = (state) => ({
});

const mapDispatch = (dispatch) => ({

});

const mergeAllProps = (stateProps, dispatchProps, ownProps) => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ const ButtonComponent = (props) => (
<div>Button</div>
);

const mapDispatchToProps = {};
const mapDispatchToProps = {

};

export const Button = connect(null, mapDispatchToProps)(ButtonComponent);
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ const mapStateToProps = (state) => ({

});

const mapDispatchToProps = {};
const mapDispatchToProps = {

};

export const Button = connect(mapStateToProps, mapDispatchToProps)(ButtonComponent);
4 changes: 3 additions & 1 deletion src/__tests__/data/connect/output/class-default-export.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ const mapStateToProps = (state) => ({

});

const mapDispatchToProps = {};
const mapDispatchToProps = {

};

export default connect(mapStateToProps, mapDispatchToProps)(Button);
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ export default (hoc) => {

});

const mapDispatchToProps = {};
const mapDispatchToProps = {

};

return connect(mapStateToProps, mapDispatchToProps)(Button);
};
4 changes: 3 additions & 1 deletion src/__tests__/data/connect/output/class-hoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ export default (hoc) => {

});

const mapDispatchToProps = {};
const mapDispatchToProps = {

};

return connect(mapStateToProps, mapDispatchToProps)(Button);
};
4 changes: 3 additions & 1 deletion src/__tests__/data/connect/output/class-named-export.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ const mapStateToProps = (state) => ({

});

const mapDispatchToProps = {};
const mapDispatchToProps = {

};

export const Button = connect(mapStateToProps, mapDispatchToProps)(ButtonComponent);
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ const mapStateToProps = (state) => ({

});

const mapDispatchToProps = {};
const mapDispatchToProps = {

};

export const Button = connect(mapStateToProps, mapDispatchToProps)(ButtonComponent);
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ const mapStateToProps = (state) => ({

});

const mapDispatchToProps = {};
const mapDispatchToProps = {

};

export default withRouter(connect(mapStateToProps, mapDispatchToProps)(Button));
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ const mapStateToProps = (state) => ({

});

const mapDispatchToProps = {};
const mapDispatchToProps = {

};

export const Button = connect(mapStateToProps, mapDispatchToProps)(ButtonComponent);
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ const mapStateToProps = (state) => ({

});

const mapDispatchToProps = {};
const mapDispatchToProps = {

};

export default connect(mapStateToProps, mapDispatchToProps)(Button);
4 changes: 3 additions & 1 deletion src/__tests__/data/connect/output/functional-hoc-bodyless.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ export default hoc => {

});

const mapDispatchToProps = {};
const mapDispatchToProps = {

};

return connect(mapStateToProps, mapDispatchToProps)(InnerComponent);
};
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ export default (hoc) => {

});

const mapDispatchToProps = {};
const mapDispatchToProps = {

};

return connect(mapStateToProps, mapDispatchToProps)(Button);
};
4 changes: 3 additions & 1 deletion src/__tests__/data/connect/output/functional-hoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ export default (hoc) => {

});

const mapDispatchToProps = {};
const mapDispatchToProps = {

};

return connect(mapStateToProps, mapDispatchToProps)(Button);
};
4 changes: 3 additions & 1 deletion src/__tests__/data/connect/output/functional-named-export.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ const mapStateToProps = (state) => ({

});

const mapDispatchToProps = {};
const mapDispatchToProps = {

};

export const Button = connect(mapStateToProps, mapDispatchToProps)(ButtonComponent);
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ const mapStateToProps = (state) => ({

});

const mapDispatchToProps = {};
const mapDispatchToProps = {

};

export default connect(mapStateToProps, mapDispatchToProps)(Component);
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ const mapStateToProps = (state) => ({

});

const mapDispatchToProps = {};
const mapDispatchToProps = {

};

export const Button = connect(mapStateToProps, mapDispatchToProps)(ButtonComponent);
9 changes: 6 additions & 3 deletions src/builders/redux-connect-builder/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ const createMapStateToPropsFunctionAst = (functionName) => {
const { doubleEndOfLine, endOfLine, indent, semicolon } = settings;
let code = '';
code += doubleEndOfLine;
code += `const ${functionName} = (state) => ({`;
code += endOfLine;
code += `const ${functionName} = (state) => ({${endOfLine}`;
code += indentLine('', indent);
code += endOfLine;
code += `})${semicolon}`;
Expand All @@ -47,9 +46,13 @@ const createMapDispatchToPropsFunctionAst = (functionName) => {
let code = '';
code += doubleEndOfLine;
if (mapToDispatchPreferObject) {
code += `const ${functionName} = {}${semicolon}${endOfLine}`;
code += `const ${functionName} = {${endOfLine}`;
code += indentLine('', indent);
code += endOfLine;
code += `}${semicolon}${endOfLine}`;
} else {
code += `const ${functionName} = (dispatch) => ({${endOfLine}`;
code += indentLine('', indent);
code += endOfLine;
code += `})${semicolon}${doubleEndOfLine}`;
}
Expand Down

0 comments on commit d6c3994

Please sign in to comment.