Created
December 4, 2017 16:21
-
-
Save MicroBenz/5c246a9f034b666b644a0cffb89a369a to your computer and use it in GitHub Desktop.
YWC15
This file contains hidden or 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
// actionCreator.js | |
import { defineAction } from 'redux-define'; | |
const appsCreator = defineAction('ywc15'); | |
export const promiseStates = ['PENDING', 'RESOLVED', 'REJECTED']; | |
export default namespace => (action, isContainPromiseStates) => ( | |
isContainPromiseStates ? | |
appsCreator.defineAction(namespace).defineAction(action, promiseStates) : | |
appsCreator.defineAction(namespace).defineAction(action).toString() | |
); | |
// app.js (duck) | |
import actionCreator from '../../utils/actionCreator'; | |
import api from '../../utils/api'; | |
const appAction = actionCreator('app'); | |
const DONE_FIRSTLOAD = appAction('DONE_FIRSTLOAD'); | |
const LOAD_REGISTER_STAT = appAction('LOAD_REGISTER_STAT', true); | |
const initialState = { | |
isFirstLoad: true, | |
registerStat: { | |
programming: 0, | |
design: 0, | |
content: 0, | |
marketing: 0 | |
} | |
}; | |
export default (state = initialState, action) => { | |
switch (action.type) { | |
case DONE_FIRSTLOAD: | |
return { | |
...state, | |
isFirstLoad: false | |
}; | |
case LOAD_REGISTER_STAT.RESOLVED: | |
return { | |
...state, | |
registerStat: action.data | |
}; | |
default: | |
return state; | |
} | |
}; | |
export const actions = { | |
doneFirstLoad: () => ({ type: DONE_FIRSTLOAD }), | |
loadRegisterStat: () => ({ | |
type: LOAD_REGISTER_STAT, | |
promise: api.get('/users/stat') | |
}) | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment