Last active
December 18, 2016 00:12
-
-
Save nickbalestra/5af168794267a07a2f4250ccf1e2321d to your computer and use it in GitHub Desktop.
A little utility to be used with redux-cycle-middleware or cycle.js in general
This file contains 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
function combineCycles(...mains) { | |
return function(sources) { | |
const sinks = mains.map(main => main(sources)) | |
const drivers = Object.keys( | |
sinks.reduce((drivers, sink) => Object.assign(drivers, sink), {}) | |
) | |
const combinedSinks = drivers | |
.reduce((combinedSinks, driver) => { | |
const driverSinks = sinks | |
.filter(sink => sink[driver]) | |
.map(sink => sink[driver]) | |
combinedSinks[driver] = xs.merge(...driverSinks) | |
return combinedSinks | |
}, {}) | |
return combinedSinks | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment