Created
August 27, 2018 19:58
-
-
Save hetmann/9351436f9d135fd215a4ec52577e37fd to your computer and use it in GitHub Desktop.
Redux Ducks - Proposal
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
// 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