Skip to content

Instantly share code, notes, and snippets.

@lmatteis
Last active November 28, 2016 15:49
Show Gist options
  • Save lmatteis/93ed8f9c88958cdb0d7527dcae8bc28c to your computer and use it in GitHub Desktop.
Save lmatteis/93ed8f9c88958cdb0d7527dcae8bc28c to your computer and use it in GitHub Desktop.
Redux-cycle-middleware
// 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