How to use the xstream.fromObservable 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 / collection / src / collection.js View on Github external
function Collection (component, sources = {}, sourceAdd$ = xs.empty(), removeSelector = noop) {
    const removeProxy$ = xs.create();
    const add$ = xs.fromObservable(sourceAdd$);
    const addReducer$ = add$.map(sourcesList => collection => {
      if (Array.isArray(sourcesList)) {
        // multiple items
        return sourcesList.reduce((collection, sources) => collection.add(sources), collection);
      } else {
        // single item
        return collection.add(sourcesList);
      }
    });
    const removeReducer$ = removeProxy$.map(item => collection => collection.remove(item));
    const reducer$ = xs.merge(removeReducer$, addReducer$);

    const emptyCollection = collection({ component, sources, removeSelector });
    const collection$ = reducer$
      .fold((collection, reducer) => reducer(collection), emptyCollection)
      .map(collection => collection.asArray());
github cyclejs / collection / src / collection.js View on Github external
function sink$ (item) {
      const key = item._id;

      if (sinks[key] === undefined) {
        const selectedSink = xs.fromObservable(mergeSelector(item));
        const sink = selectedSink.map(x =>
          isVtree(x) && x.key == null ? {...x, key} : x
        );
        // prevent sink from early completion and reinitialization
        sinks[key] = xs.merge(sink, xs.never());
      }

      return sinks[key];
    }
github cyclejs / collection / src / collection.js View on Github external
function sink$ (item) {
      const key = item._id;

      if (sinks[key] === undefined) {
        const selectedSink = xs.fromObservable(mergeSelector(item));
        const sink = selectedSink.map(x =>
          isVtree(x) && x.key == null ? {...x, key} : x
        );
        // prevent sink from early completion and reinitialization
        sinks[key] = xs.merge(sink, xs.never());
      }

      return sinks[key];
    }

    const collection$ = xs.fromObservable(sourceCollection$);
    const outputCollection$ = collection$
      .map(items => items.map(item => sink$(item)))
      .map(sinkStreams => xs.merge(...sinkStreams))
      .flatten();
    return internal
      ? outputCollection$
      : adapt(outputCollection$);
  };
github cyclejs-community / cyclic-router / src / routerify.ts View on Github external
opts.routerName
        );
        let srcs = sources;
        if (opts.omitHistory) {
            delete srcs[opts.historyName];
        }
        const sinks = main({
            ...srcs,
            [opts.routerName]: routerSource
        });
        return {
            ...sinks,
            [opts.historyName]: adapt(
                xs.merge(
                    sinks[opts.historyName] && !opts.omitHistory
                        ? xs.fromObservable(sinks[opts.historyName])
                        : xs.never(),
                    sinks[opts.routerName]
                        ? xs.fromObservable(sinks[opts.routerName])
                        : xs.never()
                )
            )
        };
    };
}
github cyclejs-community / cyclejs-sortable / src / makeSortable.ts View on Github external
function getMouseStream(
    DOM: DOMSource,
    eventTypes: string[],
    handle: string
): Stream {
    return xs.merge(
        ...eventTypes
            .slice(0, -1)
            .map(ev => xs.fromObservable(DOM.select(handle).events(ev))),
        xs
            .fromObservable(
                DOM.select(handle).events(eventTypes[eventTypes.length - 1])
            )
            .map(augmentEvent)
    ) as Stream;
}
github cyclejs / cyclejs / time / src / assert-equal.ts View on Github external
const assert = {
      state: 'pending',
      error: null,
      unexpectedErrors: [],
      finish: () => {
        checkEqual(completeStore, assert, interval, comparator);
      },
    };

    addAssert(assert);

    const actualLog$ = Time.record(actual);
    const expectedLog$ = Time.record(expected);

    xs.combine(
      xs.fromObservable(actualLog$),
      xs.fromObservable(expectedLog$)
    ).addListener({
      next([aLog, bLog]) {
        completeStore.actual = aLog;
        completeStore.expected = bLog;
      },

      complete() {
        checkEqual(completeStore, assert, interval, comparator);
      },
    });
  };
}
github cyclejs-community / cyclic-router / src / routerify.ts View on Github external
if (opts.omitHistory) {
            delete srcs[opts.historyName];
        }
        const sinks = main({
            ...srcs,
            [opts.routerName]: routerSource
        });
        return {
            ...sinks,
            [opts.historyName]: adapt(
                xs.merge(
                    sinks[opts.historyName] && !opts.omitHistory
                        ? xs.fromObservable(sinks[opts.historyName])
                        : xs.never(),
                    sinks[opts.routerName]
                        ? xs.fromObservable(sinks[opts.routerName])
                        : xs.never()
                )
            )
        };
    };
}
github cyclejs / cyclejs / time / src / assert-equal.ts View on Github external
state: 'pending',
      error: null,
      unexpectedErrors: [],
      finish: () => {
        checkEqual(completeStore, assert, interval, comparator);
      },
    };

    addAssert(assert);

    const actualLog$ = Time.record(actual);
    const expectedLog$ = Time.record(expected);

    xs.combine(
      xs.fromObservable(actualLog$),
      xs.fromObservable(expectedLog$)
    ).addListener({
      next([aLog, bLog]) {
        completeStore.actual = aLog;
        completeStore.expected = bLog;
      },

      complete() {
        checkEqual(completeStore, assert, interval, comparator);
      },
    });
  };
}