How to use the cyclejs.Rx.Observable function in cyclejs

To help you get started, we’ve selected a few cyclejs 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 erykpiast / autocompleted-select / src / js / model.js View on Github external
highlightedAutocompletionIndex$: (autocompletions$, valueChange$, hideAutocompletions$, selectedAutocompletionInput$) =>
        Rx.Observable.combineLatest(
            Rx.Observable.merge(
                Rx.Observable.merge( // reset position on text and when autocompletions list hides
                    valueChange$,
                    hideAutocompletions$
                )
                .map(() => ({ direct: 0 }))
                .delay(1), // reset after fetching value from autocompletions
                selectedAutocompletionInput$
            ),
            autocompletions$,
            (positionModifier, autocompletions) => ({ positionModifier, autocompletions })
        ).scan(0, (position, { positionModifier, autocompletions }) => {
            if(positionModifier.hasOwnProperty('modifier')) {
                position = position + positionModifier.modifier;
            } else if(positionModifier.hasOwnProperty('direct')) {
                position = positionModifier.direct;
github erykpiast / autocompleted-select / src / js / model.js View on Github external
autocompletions$: (textFieldValue$, datalistAttr$) =>
        Rx.Observable.combineLatest(
            textFieldValue$,
            datalistAttr$,
            (value, datalist) =>
                value.length ?
                datalist // choose keywords matching to value and sort them by ranking
                    .map((keywords) => ({
                        value: keywords[0], // show only the first keyword
                        // but match all of them and choose one with the highest ranking
                        score: Math.max.apply(Math, keywords.map(function(keyword, index) {
                            var index = keyword.toLowerCase().indexOf(value.toLowerCase());

                            if(index === -1) {
                                return -Infinity;
                            }

                            return (100 - index * Math.abs(keyword.length - value.length));
github ivan-kleshnin / cyclejs-examples / frontend / 1.3-hello-nodes / scripts / app.js View on Github external
// IMPORTS =========================================================================================
require("../../common/scripts/polyfills");
let {Rx, h, createStream, render} = require("cyclejs");

// DATA-SOURCE =====================================================================================
let input$ = Rx.Observable.fromPromise(
  new Promise((resolve, reject) => {
    resolve("CycleJS");
  })
);

// INTERACTION =====================================================================================
let interaction$ = createStream(vtree$ => {
  return render(vtree$, "main").interaction$;
});

// [INTERACTION] <- INTENT =========================================================================
let changeName$ = createStream(interaction$ => {
  return interaction$.choose("[name=name]", "input").map(event => event.target.value);
});

// [INTENT] <- MODEL ===============================================================================
github staltz / rxmarbles / src / components / sandbox / sandbox-output.js View on Github external
function toVTStream(diagramData, scheduler) {
  let singleMarbleStreams = diagramData.get('notifications').map(item =>
    justIncomplete(item, scheduler).delay(item.get('time'), scheduler)
  ).toArray();
  // Necessary correction to include marbles at time exactly diagramData.end:
  let correctedEndTime = diagramData.get('end') + 0.01;
  return Rx.Observable.merge(singleMarbleStreams)
    .takeUntilWithTime(correctedEndTime, scheduler)
    .publish().refCount();
}
github erykpiast / cyclejs-mock / src / inject-testing-utils.js View on Github external
Object.keys(definitionObj).forEach((name) => {
            let [ selector, event ] = name.split('@');

            if(!eventsMap.hasOwnProperty(selector)) {
                eventsMap[selector] = { };
            }

            if(definitionObj[name] instanceof Rx.Observable) {
                eventsMap[selector][event] = definitionObj[name];
            } else {
                eventsMap[selector][event] = createObservable(
                    scheduler,
                    Rx.ReactiveTest.onNext(20, definitionObj[name])
                );
            }
        });
github erykpiast / cyclejs-mock / src / inject-testing-utils.js View on Github external
let fnArgs = getParametersNames(fn).map((name) => {
            if(!(providedArgs[name] instanceof Rx.Observable)) {
                return createObservable();
            } else {
                return providedArgs[name];
            }
        });
github erykpiast / cyclejs-mock / test / inject-testing-utils.spec.js View on Github external
injectTestingUtils((mockInteractions) => {
            let mock = mockInteractions();

            assert.instanceOf(mock.choose(), Rx.Observable);
            assert.instanceOf(mock.choose('button', 'click'), Rx.Observable);
            assert.instanceOf(mock.choose('#field', 'input'), Rx.Observable);
            assert.instanceOf(mock.choose('abc', 'xyz'), Rx.Observable);
        }));
github erykpiast / cyclejs-mock / test / inject-testing-utils.spec.js View on Github external
injectTestingUtils((mockInteractions) => {
            let mock = mockInteractions();

            assert.instanceOf(mock.choose(), Rx.Observable);
            assert.instanceOf(mock.choose('button', 'click'), Rx.Observable);
            assert.instanceOf(mock.choose('#field', 'input'), Rx.Observable);
            assert.instanceOf(mock.choose('abc', 'xyz'), Rx.Observable);
        }));
github erykpiast / autocompleted-select / src / js / spec / mock.js View on Github external
fnArgs.forEach((name) => {
            if(!(args[name] instanceof Rx.Observable)) {
                args[name] = createObservable();
            }
        });
github erykpiast / autocompleted-select / src / js / intent.js View on Github external
selectedAutocompletionChange$: (mousedownOnAutocompletion$, enter$) =>
        Rx.Observable.merge(
            enter$,
            mousedownOnAutocompletion$
        ).map(() => true),
    showAutocompletions$: (focusOnField$, notEnter$) =>