Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@webbower
Last active May 4, 2020 19:16
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 webbower/a7e1418b66567a9e0856d5b21442571f to your computer and use it in GitHub Desktop.
Save webbower/a7e1418b66567a9e0856d5b21442571f to your computer and use it in GitHub Desktop.
Template for a Redux Ducks module
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