Skip to content

Instantly share code, notes, and snippets.

@MicroBenz
Created December 4, 2017 16:21
Show Gist options
  • Save MicroBenz/5c246a9f034b666b644a0cffb89a369a to your computer and use it in GitHub Desktop.
Save MicroBenz/5c246a9f034b666b644a0cffb89a369a to your computer and use it in GitHub Desktop.
YWC15
// 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