Created
February 11, 2017 00:18
-
-
Save reggi/1a75e83b9aa50e1bae36a7aa486ba736 to your computer and use it in GitHub Desktop.
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
| import {set} from 'lodash' | |
| export const epicGenerator = (generalType, fulfilledType, rejectedType, asyncCall) => { | |
| return (action$, store) => { | |
| return action$.filter(action => action.type === generalType) | |
| .flatMap(async (action) => { | |
| try { | |
| const payload = await asyncCall(action) | |
| return { | |
| type: fulfilledType, | |
| payload: payload | |
| } | |
| } catch (e) { | |
| return { | |
| type: rejectedType, | |
| error: error.message | |
| } | |
| } | |
| }) | |
| } | |
| } | |
| export const setPlus = (parent, child, options = {}) => { | |
| set(parent, child, child) | |
| if (options.append) { | |
| options.append.forEach(val => { | |
| set(parent, `${child}.${val}`, `${child}.${val}`) | |
| }) | |
| } | |
| } | |
| export const buildActions = (actions, append) => { | |
| const ACTIONS = {} | |
| actions.forEach(action => { | |
| setPlus(ACTIONS, action, {append}) | |
| }) | |
| return ACTIONS | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment