How to use the rx.Observable.fromEvent function in rx

To help you get started, we’ve selected a few rx 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 milankinen / react-reactive-toolkit / examples / 03-counters / index.js View on Github external
const App = R(({events}) => {
  const inc$ = Observable.fromEvent(events, "inc-click").map(() => +1)
  const dec$ = Observable.fromEvent(events, "dec-click").map(() => -1)

  // also React onChange is supported
  const text$ = Observable.fromEvent(events, "text-change")
    .map(e => e.target.value)
    .startWith("tsers")
    .shareReplay()

  const counter$ =
    inc$.merge(dec$)
      .startWith(0)
      .scan((val, d) => val + d, 0)
      .shareReplay()

  const style$ =
    Observable.combineLatest([text$, counter$])
      .map(([text, counter]) => text.length === counter ? "red" : "black")
      .map(color => ({color}))

  // You can emit events from reactive components by giving an object
github milankinen / react-reactive-toolkit / examples / 03-counters / index.js View on Github external
const App = R(({events}) => {
  const inc$ = Observable.fromEvent(events, "inc-click").map(() => +1)
  const dec$ = Observable.fromEvent(events, "dec-click").map(() => -1)

  // also React onChange is supported
  const text$ = Observable.fromEvent(events, "text-change")
    .map(e => e.target.value)
    .startWith("tsers")
    .shareReplay()

  const counter$ =
    inc$.merge(dec$)
      .startWith(0)
      .scan((val, d) => val + d, 0)
      .shareReplay()

  const style$ =
    Observable.combineLatest([text$, counter$])
github crucialfelix / supercolliderjs / packages / server / src / server.ts View on Github external
this.osc = dgram.createSocket("udp4");

      this.osc.on("listening", () => {
        this.processEvents.onNext(udpListening);
      });
      this.osc.on("close", e => {
        this.processEvents.onNext("udp closed: " + e);
        this.disconnect();
      });

      // pipe events to this.receive
      this._serverObservers.oscMessage = Observable.fromEvent(this.osc, "message", msgbuf => unpackMessage(msgbuf));
      this._serverObservers.oscMessage.subscribe(e => this.receive.onNext(parseMessage(e)));

      this._serverObservers.oscError = Observable.fromEvent(this.osc, "error");
      this._serverObservers.oscError.subscribe(e => {
        this.receive.onError(e);
        reject(e);
      });

      // this will trigger a response from server
      // which will cause a udp listening event.
      // After server responds then we are truly connected.
      this.callAndResponse(notify()).then(() => {
        resolve(this);
      });
    });
  }
github crucialfelix / supercolliderjs / packages / server / src / server.ts View on Github external
return new Promise((resolve, reject) => {
      const udpListening = "udp is listening";

      this.osc = dgram.createSocket("udp4");

      this.osc.on("listening", () => {
        this.processEvents.onNext(udpListening);
      });
      this.osc.on("close", e => {
        this.processEvents.onNext("udp closed: " + e);
        this.disconnect();
      });

      // pipe events to this.receive
      this._serverObservers.oscMessage = Observable.fromEvent(this.osc, "message", msgbuf => unpackMessage(msgbuf));
      this._serverObservers.oscMessage.subscribe(e => this.receive.onNext(parseMessage(e)));

      this._serverObservers.oscError = Observable.fromEvent(this.osc, "error");
      this._serverObservers.oscError.subscribe(e => {
        this.receive.onError(e);
        reject(e);
      });

      // this will trigger a response from server
      // which will cause a udp listening event.
      // After server responds then we are truly connected.
      this.callAndResponse(notify()).then(() => {
        resolve(this);
      });
    });
  }
github cyclejs / cycle-time-travel / src / intent.js View on Github external
function intent (DOM) {
  const mousePosition$ = DOM.select('.stream').events('mousemove')
    .map(getMousePosition)
    .startWith({x: 0, y: 0})

  const click$ = DOM.select('.stream').events('mousedown');
  const release$ = Observable.fromEvent(document.body, 'mouseup');

  const dragging$ = Observable.merge(
    click$.map(_ => true),
    release$.map(_ => false)
  ).startWith(false);

  const playingClick$ = DOM.select('.pause').events('click')
    .scan((previous, _) => !previous, true)
    .startWith(true);

  const playing$ = Observable.combineLatest(
    dragging$,
    playingClick$,
    (dragging, playingClick) => {
      if (dragging) {
        return false;
github alkhe / electron-cycle-media / src / mediadriver.js View on Github external
		.flatMap(event => $.fromEvent(player, event))
		.pluck('target');
github cyclejs-community / cycle-mouse-driver / src / keys-driver.js View on Github external
presses (key) {
        let keypress$ = Observable.fromEvent(document.body, 'keypress');

        if (key) {
          const code = keycode(key);

          keypress$ = keypress$.filter(event => event.keyCode === code);
        }

        return keypress$;
      }
    }
github crucialfelix / supercolliderjs / packages / server / src / internals / SendOSC.ts View on Github external
subscribe(
    onNext: (value: { type: string; payload: any }) => void,
    onError?: (value: { type: string; payload: any }) => void,
    onComplete?: () => void,
  ): Disposable {
    const msgs = Observable.fromEvent(this, "msg", msg => {
      return {
        type: "msg",
        payload: msg,
      };
    });
    const bundles = Observable.fromEvent(this, "bundle", bundle => {
      return {
        type: "bundle",
        payload: bundle,
      };
    });
    const combo = msgs.merge(bundles);
    return combo.subscribe(onNext, onError, onComplete);
  }
}
github freeCodeCamp / freeCodeCamp / client / sagas / window-saga.js View on Github external
function listenForResize(document, window) {
  return Observable.fromEvent(window, 'resize')
    .debounce(250)
    .startWith({})
    .map(() => getWindowSize(document, window));
}
github tierratelematics / prettygoat / scripts / cluster / Cluster.ts View on Github external
changes(): Observable {
        return Observable.fromEvent(this.ringpop, 'ringChanged');
    }