Skip to content

Instantly share code, notes, and snippets.

@ayroblu
Created February 19, 2017 00:04
Show Gist options
  • Save ayroblu/d2f3d192f12417ee2d1946978f49247f to your computer and use it in GitHub Desktop.
Save ayroblu/d2f3d192f12417ee2d1946978f49247f to your computer and use it in GitHub Desktop.
redux
import { SET, RESET } from '../types/user'
export function set(payload){
return {
type: SET
, payload
}
}
export function reset(){
return {
type: RESET
}
}
import { combineReducers } from 'redux'
import user from './user'
export default combineReducers({
user
})
import { SET, RESET } from '../types/user'
const initialState = {
email: 'user@example.com'
}
export default function reducer(state=initialState, action) {
switch (action.type) {
case SET:
return {...state, ...action.payload}
case RESET:
return {...initialState}
default:
return state
}
}
const prefix = 'USER/'
export const SET = prefix + 'SET'
export const RESET = prefix + 'RESET'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment