How to use the xstream/extra/fromEvent function in xstream

To help you get started, we’ve selected a few xstream examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cyclejs-community / cycle-mouse-driver / src / mouse-driver.js View on Github external
up () {
        const up$ = fromEvent(document, 'mouseup');

        return streamAdapter.adapt(up$, xstreamAdapter.streamSubscribe);
      },
      down () {
github fanduel-oss / refract / examples / visit-time / xstream / src / index.js View on Github external
const aperture = () => {
    const visible$ = fromEvent(document, 'visibilitychange')
        .map(isVisible)
        .startWith(isVisible())
    const online$ = xs
        .merge(
            fromEvent(window, 'online').mapTo(true),
            fromEvent(window, 'offline').mapTo(false)
        )
        .startWith(isOnline())

    return xs
        .combine(online$, visible$)
        .map(([online, visible]) => online && visible)
        .compose(dropRepeats())
        .map(
            onlineAndVisible =>
                onlineAndVisible
                    ? xs
                          .periodic(10)
                          .mapTo({
                              type: 'TICK'
                          })
                          .startWith({ type: 'RESUME' })
github cyclejs-community / cycle-mouse-driver / src / mouse-driver.js View on Github external
down () {
        const down$ = fromEvent(document, 'mousedown');

        return streamAdapter.adapt(down$, xstreamAdapter.streamSubscribe);
      },
      click () {
github cyclejs-community / cycle-mouse-driver / src / mouse-driver.js View on Github external
positions () {
        const positions$ = fromEvent(document, 'mousemove')
          .map(ev => {
            return {x: ev.clientX, y: ev.clientY};
          }
        )
        .startWith({x: 0, y: 0});

        return streamAdapter.adapt(positions$, xstreamAdapter.streamSubscribe);
      },
      up () {
github fanduel-oss / refract / examples / visit-time / xstream / src / index.js View on Github external
const aperture = () => {
    const visible$ = fromEvent(document, 'visibilitychange')
        .map(isVisible)
        .startWith(isVisible())
    const online$ = xs
        .merge(
            fromEvent(window, 'online').mapTo(true),
            fromEvent(window, 'offline').mapTo(false)
        )
        .startWith(isOnline())

    return xs
        .combine(online$, visible$)
        .map(([online, visible]) => online && visible)
        .compose(dropRepeats())
        .map(
            onlineAndVisible =>
                onlineAndVisible
github wellcometrust / wellcomecollection.org / client / js / utils / dom-events.js View on Github external
import fromEvent from 'xstream/extra/fromEvent';
import debounce from 'xstream/extra/debounce';
import throttle from 'xstream/extra/throttle';

export const onWindowResizeDebounce$ = fromEvent(window, 'resize').compose(debounce(500));
export const onWindowScrollThrottle$ = fromEvent(window, 'scroll').compose(throttle(100));
export const onWindowScrollDebounce$ = fromEvent(window, 'scroll').compose(debounce(500));
export const onWindowOrientationChange$ = fromEvent(window, 'orientationchange');
export const documentReadyState$ =
  fromEvent(document, 'readystatechange')
    .map(() => document.readyState)
    .startWith(document.readyState)
    .remember();
github wellcometrust / wellcomecollection.org / client / js / utils / dom-events.js View on Github external
import fromEvent from 'xstream/extra/fromEvent';
import debounce from 'xstream/extra/debounce';
import throttle from 'xstream/extra/throttle';

export const onWindowResizeDebounce$ = fromEvent(window, 'resize').compose(debounce(500));
export const onWindowScrollThrottle$ = fromEvent(window, 'scroll').compose(throttle(100));
export const onWindowScrollDebounce$ = fromEvent(window, 'scroll').compose(debounce(500));
export const onWindowOrientationChange$ = fromEvent(window, 'orientationchange');
export const documentReadyState$ =
  fromEvent(document, 'readystatechange')
    .map(() => document.readyState)
    .startWith(document.readyState)
    .remember();
github fanduel-oss / refract / examples / routing / xstream / src / index.js View on Github external
const activeTab$ = component.observe('setActiveTab')

    return xs.merge(
        xs.of({
            type: 'NAVIGATION',
            replace: true,
            state: { activeTab: initialProps.activeTab }
        }),

        activeTab$.map(activeTab => ({
            type: 'NAVIGATION',
            replace: false,
            state: { activeTab }
        })),

        fromEvent(window, 'popstate').map(evt => ({
            type: 'STATE',
            state: evt.state || { activeTab: null }
        }))
    )
}
github cyclejs / cyclejs / examples / advanced / animated-letters / src / main.js View on Github external
  Keydown: () => fromEvent(document, 'keydown'),
  DOM: makeDOMDriver('#main-container'),
github cyclejs-community / cycle-mouse-driver / src / mouse-driver.js View on Github external
click () {
        const click$ = fromEvent(document, 'click');

        return streamAdapter.adapt(click$, xstreamAdapter.streamSubscribe);
      }
    };