How to use rx - 10 common examples

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 CharlieHess / slack-poker-bot / tests / player-interaction-spec.js View on Github external
beforeEach(function() {
      messages = new rx.Subject();
      channel = { 
        send: function() { 
          // NB: Posting a message to the channel returns an editable message
          // object, which we're faking out here.
          return { updateMessage: function() { } };
        } 
      };
      scheduler = new rx.HistoricalScheduler();
      players = [];
    });
github pH200 / cycle-react / src / dom-user.js View on Github external
_defineRootElemStream() {
    // Create rootElem stream and automatic className correction
    let originalClasses = (this._domContainer.className || '').trim().split(/\s+/);
    //console.log('%coriginalClasses: ' + originalClasses, 'color: lightgray');
    this._rawRootElem$ = new Rx.Subject();
    this._rootElem$ = this._rawRootElem$
      .map(function fixRootElemClassName(rootElem) {
        let previousClasses = rootElem.className.trim().split(/\s+/);
        let missingClasses = originalClasses.filter(function (clss) {
          return previousClasses.indexOf(clss) < 0;
        });
        //console.log('%cfixRootElemClassName(), missingClasses: ' + missingClasses,
        //  'color: lightgray');
        rootElem.className = previousClasses.concat(missingClasses).join(' ');
        //console.log('%c  result: ' + rootElem.className, 'color: lightgray');
        //console.log('%cEmit rootElem$ ' + rootElem.tagName + '.' + rootElem.className,
        //  'color: #009988');
        return rootElem;
      })
      .shareReplay(1);
  }
github laszlokorte / tams-tools / app / components / pla / index.js View on Github external
.distinctUntilChanged(
        (s) => s,
        dimenstionsHaveNotChanged
      )
      // Center the camera vertically and align it to the top
      .map(() => ({weightX: 0.5, weightY: 0})),
  });

  return {
    DOM: O.combineLatest(
      // merge the cost panel into the vtree
      pla$.map(costPanel),
      stage.DOM,
      (a,b) => [a,b]
    ).map(wrapInDiv),
    preventDefault: O.merge([
      actions.preventDefault,
      stage.preventDefault,
    ]),
  };
};
github pusher-community / cyclejs-realtime-chat / src / app.js View on Github external
const model = actions => {
    const message$ = Rx.Observable.merge(
      actions.changeMessage$,
      // we listen to this observable
      // because when the submit button is clicked
      // we want to clear the message input out
      actions.submitMessage$.map(x => '')
    ).startWith('')

    return Observable.combineLatest(
      allPusherMessages$,
      actions.submitUsername$.startWith(''),
      message$,
      (pusherMessages, username, message) => ({ pusherMessages, username, message })
    );
  };
github tomlarkworthy / animaxe / dist / examples / example6.js View on Github external
Slider.rectangular = function (value, postprocessor) {
        var hotspot = Ax.create()
            .withinPath(Ax.create()
            .lineTo([20, 0])
            .lineTo([20, 20])
            .lineTo([0, 20])
            .lineTo([0, 0]));
        value.subscribe(function (x) { return console.log("pre construction value changed", x); });
        var slider = new Slider(hotspot, new events.ComponentMouseState(), new events.ComponentMouseState(), value, Ax.create().fillStyle("red"), /* pressed */ Ax.create().fillStyle("orange"), /* over */ Ax.create().fillStyle("white") /* idle */); /* idle */
        if (postprocessor)
            postprocessor(slider);
        return slider;
    };
    return Slider;
})(Ax.Operation);
var value = new Rx.BehaviorSubject(0);
//each frame, first draw black background to erase the previous contents
animator.play(Ax.create().fillStyle(Parameter.rgba(Parameter.updateFrom(0, value).mapValue(function (x) { return x * 2.5; }), 0, 0, 1)).fillRect([0, 0], [100, 100]));
animator.play(Ax.create()
    .pipe(Slider.rectangular(value)));
helper.playExample("@name", 2, animator, 100, 100);
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 esp / esp-js / packages / esp-js-ui / src / ui / modules / prerequisites / defaultPrerequisiteRegister.ts View on Github external
constructor() {
        super();

        let loadDisposable = new Rx.SingleAssignmentDisposable();
        this.addDisposable(loadDisposable);

        this._stream = Rx.Observable.empty();
        this._publishedStream = Rx.Observable.defer(() => {
            // We close over _stream so that we allow the class to modify
            // it (see registerStream function)
            return this._stream;
        })
        // When we load, stop on the first error result we get
        // But yield it back to the consumer so they know it stopped
        .takeUntilInclusive((result: LoadResult) =>  result.stage === ResultStage.Error)
        .multicast(new Rx.ReplaySubject(1))
        .lazyConnect(loadDisposable);
    }
github laszlokorte / tams-tools / app / components / kv / index.js View on Github external
export default ({
  DOM, // DOM driver source
  globalEvents, // globalEvent driver sources
}) => {
  const openData$ = new Subject();
  const importExpression$ = new Subject();
  const viewSetting$ = new Subject();

  const actions = intent({
    DOM, globalEvents,
    openData$,
    importExpression$,
    viewSetting$: viewSetting$,
  });

  const state$ = model(O.empty(), actions);

  const plaData$ = state$.map(({state}) =>
    toPLA(state.diagram, state.currentKvMode, state.currentLoop.cube)
  ).share();

  const jsonData$ = state$.map(({state}) =>
github panacloud / learn-angular / step9_gulp_router / node_modules / angular2 / src / facade / async.js View on Github external
function EventEmitter() {
        _super.call(this);
        // System creates a different object for import * than Typescript es5 emit.
        if (Rx.hasOwnProperty('default')) {
            this._subject = new Rx.default.Rx.Subject();
            this._immediateScheduler = Rx.default.Rx.Scheduler.immediate;
        }
        else {
            this._subject = new Rx.Subject();
            this._immediateScheduler = Rx.Scheduler.immediate;
        }
    }
    EventEmitter.prototype.observer = function (generator) {