From d76f3afdf2e3ab525b1fee2254da27d677769c11 Mon Sep 17 00:00:00 2001 From: Seong Yong-ju Date: Wed, 25 Dec 2019 22:46:48 +0900 Subject: [PATCH] Improve some Redux snippets --- snippets/rjsx-mode/Redux/hocredux | 18 +++++++++--------- snippets/rjsx-mode/Redux/rcredux | 6 +++--- snippets/rjsx-mode/Redux/reduxmap | 16 +++++++++++----- snippets/rjsx-mode/Redux/rncredux | 12 ++++++------ snippets/rjsx-mode/Redux/rxreducer | 9 ++++----- 5 files changed, 33 insertions(+), 28 deletions(-) diff --git a/snippets/rjsx-mode/Redux/hocredux b/snippets/rjsx-mode/Redux/hocredux index 41dfd35..b1e455a 100644 --- a/snippets/rjsx-mode/Redux/hocredux +++ b/snippets/rjsx-mode/Redux/hocredux @@ -9,16 +9,8 @@ import React from 'react' import PropTypes from 'prop-types' import { connect } from 'react-redux' -export const mapStateToProps = state => ({ - -}) - -export const mapDispatchToProps = { - -} - export const ${1:hocComponentName} = (WrappedComponent) => { - const hocComponent = ({ ...props }) => + const hocComponent = (props) => hocComponent.propTypes = { } @@ -26,4 +18,12 @@ export const ${1:hocComponentName} = (WrappedComponent) => { return hocComponent } +const mapStateToProps = (state, ownProps) => ({ + +}) + +const mapDispatchToProps = (dispatch, ownProps) => ({ + +}) + export default WrapperComponent => connect(mapStateToProps, mapDispatchToProps)(${1:hocComponentName}(WrapperComponent)) \ No newline at end of file diff --git a/snippets/rjsx-mode/Redux/rcredux b/snippets/rjsx-mode/Redux/rcredux index 497d5cb..83a6a10 100644 --- a/snippets/rjsx-mode/Redux/rcredux +++ b/snippets/rjsx-mode/Redux/rcredux @@ -23,12 +23,12 @@ export class ${1:${TM_FILENAME_BASE}} extends Component { } } -const mapStateToProps = (state) => ({ +const mapStateToProps = (state, ownProps) => ({ }) -const mapDispatchToProps = { +const mapDispatchToProps = (dispatch, ownProps) => ({ -} +}) export default connect(mapStateToProps, mapDispatchToProps)(${1:${TM_FILENAME_BASE}}) \ No newline at end of file diff --git a/snippets/rjsx-mode/Redux/reduxmap b/snippets/rjsx-mode/Redux/reduxmap index f9146f9..199bcdb 100644 --- a/snippets/rjsx-mode/Redux/reduxmap +++ b/snippets/rjsx-mode/Redux/reduxmap @@ -5,10 +5,16 @@ # key: reduxmap # -- -const mapStateToProps = (state) => ({ - ${1} +const mapStateToProps = (state, ownProps) => ({ + }) -const mapDispatchToProps = { - -} \ No newline at end of file +const mapDispatchToProps = (dispatch, ownProps) => ({ + +}) + +const mergeProps = (stateProps, dispatchProps, ownProps) => ({ + ...ownProps, + ...dispatchProps, + ...stateProps, +}) \ No newline at end of file diff --git a/snippets/rjsx-mode/Redux/rncredux b/snippets/rjsx-mode/Redux/rncredux index 78dedf3..4cb3321 100644 --- a/snippets/rjsx-mode/Redux/rncredux +++ b/snippets/rjsx-mode/Redux/rncredux @@ -18,18 +18,18 @@ export class ${1:${TM_FILENAME_BASE}} extends Component { render() { return ( - ${2:textInComponent} + ${2:textInComponent} ) } } -const mapStateToProps = (state) => ({ - +const mapStateToProps = (state, ownProps) => ({ + }) -const mapDispatchToProps = { - -} +const mapDispatchToProps = (dispatch, ownProps) => ({ + +}) export default connect(mapStateToProps, mapDispatchToProps)(${1:${TM_FILENAME_BASE}}) \ No newline at end of file diff --git a/snippets/rjsx-mode/Redux/rxreducer b/snippets/rjsx-mode/Redux/rxreducer index fe7e476..951f5e4 100644 --- a/snippets/rjsx-mode/Redux/rxreducer +++ b/snippets/rjsx-mode/Redux/rxreducer @@ -11,11 +11,10 @@ const initialState = { export default (state = initialState, { type, payload }) => { switch (type) { + case ${1:typeName}: + return { ...state, ...payload } - case ${1:typeName}: - return { ...state, ...payload } - - default: - return state + default: + return state } } \ No newline at end of file