Skip to content

Instantly share code, notes, and snippets.

@johncmunson
Created February 16, 2017 09:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johncmunson/5e32727bea2a0d589a1c5cd1a598bbd4 to your computer and use it in GitHub Desktop.
Save johncmunson/5e32727bea2a0d589a1c5cd1a598bbd4 to your computer and use it in GitHub Desktop.
'configure store':
'prefix': 'rdStore'
'body': """
export default function configureStore(preloadedState) {
return createStore(
rootReducer,
preloadedState,
applyMiddleware(
$1
)
)
}
"""
'root reducer':
'prefix': 'rdRootReducer'
'body': """
const rootReducer = combineReducers({
${1:key}: ${2:keyReducer},
});
"""
'reducer':
'prefix': 'rdReducer'
'body': """
export default function ${1:exampleReducer}(state = ${2:'default'}, action) {
switch(action.type){
case ${3:'UPDATE_EXAMPLE'}: {
return action.example
}
default: {
return state
}
}
}
"""
'action creator':
'prefix': 'rdAction'
'body': """
export default function ${1:fetchDataSuccess}(${2:data}) {
return {
type: '${3:FETCH_DATA_SUCCESS}',
payload: ${4:data}
}
}
"""
'thunk action creator':
'prefix': 'rdThunk'
'body': """
export default function ${1:fetchData}(param) {
return function(dispatch) {
dispatch(${2:fetchDataRequest}())
return fetch(`http://rest.learncode.academy/api/wstern/users`)
.then(response => response.json())
.then(json => {
dispatch(${3:fetchDataSuccess}(json))
})
.catch(err => dispatch(${4:fetchDataFailure}(err)))
}
}
"""
'mapStateToProps':
'prefix': 'rdMapState'
'body': """
const mapStateToProps = (state) => (
{
${1:prop}: ${2:state.prop}
}
)
"""
'mapDispatchToProps':
'prefix': 'rdMapDispatch'
'body': """
const mapDispatchToProps = (dispatch) => (
{
handleClick: (input) => {
dispatch(fetchData(input))
}
}
)
"""
'connect':
'prefix': 'rdConnect'
'body': 'connect(mapStateToProps, mapDispatchToProps)(${1:Component})'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment