Skip to content

Instantly share code, notes, and snippets.

@dmitriid
Last active April 1, 2016 09:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dmitriid/ff769961917debcee1fade4f796b8f70 to your computer and use it in GitHub Desktop.
Save dmitriid/ff769961917debcee1fade4f796b8f70 to your computer and use it in GitHub Desktop.
// @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$)
}
}
@dmitriid
Copy link
Author

dmitriid commented Apr 1, 2016

Also

import {Observable as O} from 'rx';

// This driver captures global events
// and provides them as Observable
export const globalEventDriver = () => {
  return {
    events: (eventName) => {
      return O.fromEventPattern(
        (h) => {
          document.addEventListener(eventName, h, true);
        },
        (h) => {
          document.removeEventListener(eventName, h, true);
        }
      );
    },
  };
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment