Last active
April 13, 2020 19:27
-
-
Save zaceno/04e2c435a11eb0622d5c73ef5b5c3ca5 to your computer and use it in GitHub Desktop.
define effect creator for hyperapp
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
export default (g => f => (...a) => [g, { f, a }])((d, { f, a }) => f(d, ...a)) | |
/* | |
Usage like: | |
import fx from 'fx.js' | |
const jsonLoader = fx((dispatch, url, then) => | |
fetch(url) | |
.then(response => response.json()) | |
.then(data => dispatch(then, data) | |
) | |
... | |
const LoadAction => (state, url) => [ | |
{...state, loading: true}, | |
jsonLoader(url, ResultAction) | |
] | |
...or... | |
const jsonLoader = fx((dispatch, {url, action}) => | |
fetch(url) | |
.then(respnse => response.json()) | |
.then(data => dispatch(action, data)) | |
) | |
... | |
const LoadAction => (state, url) => [ | |
{...state, loading: true}, | |
jsonLoader({url, action: ResultAction}) | |
] | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment