Created
February 19, 2017 00:04
-
-
Save ayroblu/d2f3d192f12417ee2d1946978f49247f to your computer and use it in GitHub Desktop.
redux
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
import { SET, RESET } from '../types/user' | |
export function set(payload){ | |
return { | |
type: SET | |
, payload | |
} | |
} | |
export function reset(){ | |
return { | |
type: RESET | |
} | |
} |
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
import { combineReducers } from 'redux' | |
import user from './user' | |
export default combineReducers({ | |
user | |
}) |
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
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 | |
} | |
} |
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 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