How to use the rx.Observable.of 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 freeCodeCamp / freeCodeCamp / common / app / routes / Challenges / redux / challenge-epic.js View on Github external
return createErrorObservable(
            new Error('Next Challenge could not be found')
          );
      }
      if (nextChallenge.isLocked) {
        return Observable.of(
          makeToast({
            message: 'The next challenge has not been unlocked. ' +
            'Please revisit the required (*) challenges ' +
            'that have not been passed yet. ',
            timeout: 15000
          }),
          onRouteCurrentChallenge()
        );
      }
      return Observable.of(
        // normally we wouldn't need to add the lang as
        // addLangToRoutesEnhancer should add langs for us, but the way
        // enhancers/middlewares and RFR orders things this action will not
        // see addLangToRoutesEnhancer and cause RFR to render NotFound
        onRouteChallenges({ lang, ...nextChallenge }),
        makeToast({ message: 'Your next challenge has arrived.' })
      );
    });
}
github milankinen / stanga / test / flatMerge.js View on Github external
it("merges the values from the demuxed list", done => {
    const list$$ = O.merge(
      O.just([{A: O.of("a1_1"), B: O.of("b1_1")}, {A: O.of("a1_21", "a1_22"), B: O.of("b1_2")}]),
      O.just([{A: O.of("a2_1"), B: O.of("b2_1")}, {A: O.of("a2_2"), B: O.of("b2_2")}]).delay(1)
    )
    const out = flatMerge(list$$, "A")
    out.A.bufferWithCount(5).subscribe(x => {
      x.should.deepEqual(["a1_1", "a1_21", "a1_22", "a2_1", "a2_2"])
      done()
    })
  })
github cyclejs-community / cyclic-router / test / rx.js View on Github external
() => {
        const history = createServerHistory('/')
        const router = makeRouterDriver(history, switchPath)(Observable.of('/'), RxAdapter)
          .path('/')
        assert.notStrictEqual(router.path, null)
        assert.strictEqual(typeof router.path, 'function')
        assert.notStrictEqual(router.define, null)
        assert.strictEqual(typeof router.define, 'function')
        assert.notStrictEqual(router.history$, null)
        assert.strictEqual(typeof router.history$, 'object')
        assert.strictEqual(typeof router.history$.subscribe, 'function')
        assert.notStrictEqual(router.createHref, null)
        assert.strictEqual(typeof router.createHref, 'function')
      })
github TylorS / cycle-snabbdom / test / node / html-render.js View on Github external
function app () {
        return {
          html: Observable.of(h('div.test-element', [
            Observable.of(h('div.a-nice-element', [
              String('foobar'),
              Observable.of(h('h3.myelementclass'))
            ]))
          ]))
        }
      }
      let {sinks, sources} = Cycle.run(app, {
github TylorS / cycle-snabbdom / test / browser / render.js View on Github external
function main () {
      return {
        DOM: Observable.of(
          div('.my-render-only-container', [
            h2('Cycle.js framework')
          ])
        )
      }
    }
github TylorS / cycle-snabbdom / test / browser / isolation.js View on Github external
function App (sources) {
      const triangleElement$ = sources.DOM.select('.triangle').elements

      const svgTriangle = svg({width: 150, height: 150}, [
        svg.polygon({
          attrs: {
            class: 'triangle',
            points: '20 0 20 150 150 20'
          }
        })
      ])

      return {
        DOM: Observable.of(svgTriangle),
        triangleElement: triangleElement$
      }
    }
github stomita / rxdux / src / index.js View on Github external
export function mergeStores(...stores) {
  const cstates$ = stores.map((cstore) => cstore.getObservable());
  const state$ = Observable.of({})
    .concat(Observable.merge(...cstates$))
    .scan((state, cstate) => {
      return Object.keys(cstate).reduce((s, prop) => {
        const value = cstate[prop];
        return s[prop] === value ? s : { ...s, [prop]: value };
      }, state);
    })
    .skip(1)
    .distinctUntilChanged()
    .shareReplay(1)
  ;
  const action$ = new Subject();
  action$.subscribe((action) => {
    stores.forEach((cstore) => cstore.dispatch(action));
  });
  return new Store(action$, state$);
github freeCodeCamp / freeCodeCamp / common / app / routes / Challenges / redux / completion-epic.js View on Github external
const body = { ...challengeInfo, _csrf };
      const saveChallenge = postJSON$(url, body)
        .retry(3)
        .map(({ points, lastUpdated, completedDate }) =>
          submitChallengeComplete(
            username,
            points,
            { ...challengeInfo, lastUpdated, completedDate }
          )
        )
        .catch(createErrorObservable);
      const challengeCompleted = Observable.of(moveToNextChallenge());
      return Observable.merge(saveChallenge, challengeCompleted)
        .startWith({ type: types.submitChallenge.start });
    }),
    Observable.of(moveToNextChallenge())
  );
}
github freeCodeCamp / freeCodeCamp / api-server / common / models / user.js View on Github external
User.prototype.getCompletedChallenges$ = function getCompletedChallenges$() {
    if (
      Array.isArray(this.completedChallenges) &&
      this.completedChallenges.length
    ) {
      return Observable.of(this.completedChallenges);
    }
    const id = this.getId();
    const filter = {
      where: { id },
      fields: { completedChallenges: true }
    };
    return this.constructor.findOne$(filter).map(user => {
      this.completedChallenges = user.completedChallenges;
      return user.completedChallenges;
    });
  };
github Netflix / falcor-router / src / run / authorize.js View on Github external
module.exports = function authorize(routerInstance, match, next) {
    if (!match.authorize) {
        return Observable.
            of(true).
            flatMap(function() { return next; });
    }

    var out = match.authorize.call(routerInstance, match);
    return outputToObservable(out).
        doAction(function(isAuthorized) {
            if (!isAuthorized) {
                throw new JSONGraphError({
                    $type: $type.$error,
                    value: {
                        unauthorized: true,
                        message: 'unauthorized'
                    }
                });
            }