JSFiddle - React, Tailwind, and code Playground
by Vladymyr Shevchuk
Babel + JSX
const createAsyncActions = (scope, /*options*/) => {
const defaultActions = ['request', 'success', 'error'];
const asyncActions = defaultActions.reduce((accum, actionName) => {
const type = `${scope}/${actionName}`;
const asyncAction = data => {
return {
type,
payload: {
data
}
};
};
accum[actionName] = asyncAction;
asyncAction.toString = () => type;
return accum;
}, {});
return asyncActions;
};
const actions = createAsyncActions('@test');
const reducerObj = {
[actions.success]: () => {
console.error('some reducer');
}
}
console.error('actions', actions);
console.error('actions', actions.success);
console.error('reducerObj', reducerObj);