How to use the xstream.empty 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 Widdershin / cycle-restart / src / restartable.js View on Github external
export default function restartable (driver, opts = {}) {
  const {log$, addLogEntry, replaceLog} = createLog$();
  // TODO - dispose log subscription
  log$.addListener(subscribe(() => {}));

  const streams = {};

  const pauseSinksWhileReplaying = opts.pauseSinksWhileReplaying === undefined ? true : opts.pauseSinksWhileReplaying;
  const pause$ = (opts.pause$ || xs.empty()).startWith(true);
  const replayOnlyLastSink = opts.replayOnlyLastSink || false;

  let replaying;
  const isReplaying = () => replaying;
  const setReplaying = (newReplaying) => replaying = newReplaying;
  const finishedReplay$ = xs.create();

  function restartableDriver (sink$, Time) {
    const filteredSink$ = xs.create();
    const lastSinkEvent$ = xs.createWithMemory();

    if (sink$) {
      if (isReplaying() && replayOnlyLastSink)  {
        lastSinkEvent$.map(lastEvent => finishedReplay$.mapTo(lastEvent)).flatten().take(1).addListener(subscribe((event) => {
          filteredSink$.shamefullySendNext(event);
        }));
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$
github cyclejs / cyclejs / html / src / HTMLSource.ts View on Github external
public select(selector: string): HTMLSource {
    return new HTMLSource(xs.empty(), this._name);
  }
github cyclejs / cyclejs / html / src / HTMLSource.ts View on Github external
constructor(html$: Stream, private _name: string) {
    this._html$ = html$;
    this._empty$ = adapt(xs.empty());
  }
github cyclejs / cyclejs / dom / src / HTMLSource.ts View on Github external
public select(selector: string): DOMSource {
    return new HTMLSource(xs.empty(), this._name);
  }
github cyclejs / react / src / ReactSource.ts View on Github external
public events(eventType: string): Stream {
    if (this._selector === null) {
      return adapt(xs.empty());
    } else {
      return adapt(this._scope.getHandler(this._selector, eventType));
    }
  }
github cyclejs / collection / src / collection.js View on Github external
add (additionalSources = {}) {
        const newItem = makeItem(component, {...sources, ...additionalSources});
        const selectedSink = removeSelector(newItem) || xs.empty();
        const removeSink = xs.fromObservable(selectedSink);
        newItem._remove$ = removeSink.take(1).mapTo(newItem);

        return collection(
          options,
          [...items, newItem]
        );
      },
github cyclejs / cyclejs / dom / src / mockDOMSource.ts View on Github external
constructor(private _mockConfig: MockConfig) {
    if (_mockConfig.elements) {
      this._elements = _mockConfig.elements as FantasyObservable;
    } else {
      this._elements = adapt(xs.empty());
    }
  }
github cyclejs-community / cycle-canvas / src / canvas-driver.js View on Github external
const rootElementWithDefaults = Object.assign(
          {},
          defaults,
          rootElement
        )

        const instructions = translateVtreeToInstructions(rootElementWithDefaults)

        renderInstructionsToCanvas(instructions, context)
      },
      error: e => { throw e },
      complete: () => null
    })

    return adapt(xs.empty())
  }
github cyclejs / cyclejs / native-screen / src / ScreenSource.ts View on Github external
public events(eventType: string): Stream {
    if (this.selector === null) {
      return adapt(xs.empty());
    } else {
      return adapt(this.ctx.getHandler(this.selector, eventType));
    }
  }
}