Last active
May 4, 2020 19:16
-
-
Save webbower/a7e1418b66567a9e0856d5b21442571f to your computer and use it in GitHub Desktop.
Template for a Redux Ducks module
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const prop = key => obj => obj[key]; | |
// Action Types | |
const MY_ACTION = '{my}-app/{module}/MY_ACTION'; | |
// Action Creators | |
export const myAction = (value) => ({ | |
type: MY_ACTION, | |
payload: value, | |
}); | |
// Selectors | |
export const getValue = prop('value'); | |
// Initial State | |
const getInitialState = ({ value = 'foo' } = {}) => ({ | |
value, | |
}); | |
// Reducer | |
export default function reducer(state = getInitialState(), action = {}) { | |
switch(action.type) { | |
case MY_ACTION: | |
return { ...state, value: action.payload }; | |
default: | |
return state; | |
} | |
} | |
// Middleware | |
export const myMiddleware = store => next => action => { | |
next(action); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment