Skip to content

Instantly share code, notes, and snippets.

@hetmann
Created August 27, 2018 19:58
Show Gist options
  • Save hetmann/9351436f9d135fd215a4ec52577e37fd to your computer and use it in GitHub Desktop.
Save hetmann/9351436f9d135fd215a4ec52577e37fd to your computer and use it in GitHub Desktop.
Redux Ducks - Proposal
// React - Redux Ducks proposal
// https://github.com/erikras/ducks-modular-redux
// Actions
const LOAD_PROFILE = 'instagram/profile/LOAD';
const EDIT_PROFILE = 'instagram/profile/EDIT';
// Initial state
const INITIAL_STATE = {
profile: {}
}
// Reducer
export default function reducer(state = INITIAL_STATE, action = {}) {
switch (action.type) {
case LOAD_PROFILE:
return {
...state,
profile: action.payload
}
case EDIT_PROFILE:
return {
...state,
profile: {
...state.profile,
...action.payload
}
}
default:
return state;
}
}
// Action Creators
export function loadProfile(payload) {
return {
type: LOAD_PROFILE,
payload: payload
};
}
export function editProfile(payload) {
return {
type: EDIT_PROFILE,
payload: payload
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment