Last active
April 1, 2016 09:12
-
-
Save dmitriid/ff769961917debcee1fade4f796b8f70 to your computer and use it in GitHub Desktop.
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
// @mariuslundgard | |
// The component | |
import {pluckSwitch} from './stream-helpers' | |
function main (sources) { | |
const sinks$ = NodeComponent({...sources}) | |
// etc. | |
return { | |
DOM: pluckSwitch('DOM', sinks$), | |
midi$: pluckSwitch('midi$', sinks$) | |
// etc. | |
} | |
} | |
// stream-helpers.js | |
export function pluckSwitch (key, stream) { | |
return stream | |
.filter((s) => s[key]) | |
.map((s) => s[key]) | |
.switch() | |
} | |
//// fixed example | |
import {pluckSwitch} from './stream-helpers' | |
function main (sources) { | |
const sinks$ = sources.location$.map((location) => { | |
// do route matching here | |
return RouteComponent({ | |
...sources, | |
location$: Observable.of(location) | |
}) | |
}) | |
return { | |
DOM: pluckSwitch('DOM', sinks$), | |
location$: pluckSwitch('location$', sinks$) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Also