Last active
November 28, 2016 15:49
-
-
Save lmatteis/93ed8f9c88958cdb0d7527dcae8bc28c to your computer and use it in GitHub Desktop.
Redux-cycle-middleware
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
// Here's how Async is done using Redux-Observable. | |
// The problem is that we still have side-effects in our epics (ajax.getJSON) | |
const fetchUserEpic = action$ => | |
action$.ofType(FETCH_USER) | |
.mergeMap(action => | |
ajax.getJSON(`https://api.github.com/users/${action.payload}`) | |
.map(fetchUserFulfilled) | |
); | |
// With Cycle.js we can push them even further outside our app using drivers. | |
// sources.ACTION is the same action stream used in "epics" | |
function main(sources) { | |
let request$ = sources.ACTION.ofType(FETCH_USER) | |
.map(action => { | |
url: `https://api.github.com/users/${action.payload}`, | |
category: 'hello', | |
}); | |
let action$ = sources.HTTP | |
.select('hello') | |
.flatten() | |
.map(fetchUserFulfilled); | |
return { | |
ACTION: action$, | |
HTTP: request$ | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment