How to use the xstream.create 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 sarimarton / powercycle / src / util / logical.js View on Github external
export function getConditionalCmp (cond, getCmp) {
  const cond$ = isStream(cond)
    ? cond
    // xs.of() is insufficient, because it must be a memory stream
    : xs.create().startWith(cond)

  if (!(cond$ instanceof MemoryStream)) {
    console.warn('Conditional stream should be a MemoryStream')
  }

  return getDynamicCmp (
    cond$.fold(
      (acc, next) => ({ cond: next, key: String(Boolean(next)) }),
      { cond: false, key: 'false' }
    ),
    next => getCmp(next.cond)
  )
}
github Widdershin / cycle-restart / src / restartable.js View on Github external
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);
        }));
      }

      if (pauseSinksWhileReplaying) {
        sink$.compose(pausable(pause$)).filter(() => !isReplaying()).addListener({
          next: (ev) => filteredSink$.shamefullySendNext(ev),
          error: (err) => console.error(err),
          complete: () => {}
        });
      } else {
github staltz / manyverse / src / ssb / opinions / hook.ts View on Github external
create: (api: any) => {
    const stream: Stream = xs.create();
    return nest({
      'sbot.hook': {
        publish: (msg: Msg) => {
          stream.shamefullySendNext(msg);
        },
        publishStream: () => stream,
      },
    });
  },
};
github jvanbruegge / adcs_plot / src / websocketDriver.ts View on Github external
return () => {
        return xs.create({
            start: listener => {
                websocket.onmessage = (msg : MessageEvent) => listener.next(msg);
            },
            stop: () => {}
        })
        .map((msg : MessageEvent) => {
            const json : any = JSON.parse(msg.data);
            return {
                ...json,
                time: new Date(json.time)
            };
        });
    };
}
github cyclejs / cyclejs / examples / advanced / many / src / List.js View on Github external
function List(sources) {
  const proxyItemRemove$ = xs.create();
  const action$ = intent(sources.DOM, proxyItemRemove$);
  const itemWrapper = makeItemWrapper(sources.DOM);
  const items$ = model(action$, itemWrapper);
  const itemRemove$ = items$
    .map(items => xs.merge(...items.map(item => item.Remove)))
    .flatten();
  proxyItemRemove$.imitate(itemRemove$);
  const vtree$ = view(items$);

  return {
    DOM: vtree$
  };
}
github shinima / trips-editor / src / components / Menubar.tsx View on Github external
export default function Menubar({
  DOM: domSource,
  state: state$,
  appHistory: appHistory$,
}: Sources): Sinks {
  const nextActiveCategoryProxy$ = xs.create()

  const activeCategory$ = nextActiveCategoryProxy$.dropRepeats().startWith(null)

  const closeWhenBlur$ = domSource
    .select('.menubar')
    .events('blur')
    .mapTo(null)

  const closeWhenMakeIntent$ = domSource
    .select('.menu-item')
    .events('click')
    .filter(e => !e.ownerTarget.classList.contains('disabled'))
    .mapTo(null)

  const clickToToggleCategory$ = domSource
    .select('.category .title')
github rapyuta-robotics / amphion / src / data / ros.ts View on Github external
this.internalListener = (message: Message) => {
          if (this.isStreamPaused) {
            return;
          }
          listener.next(message as T);
        };
        this.topic.subscribe(this.internalListener);
      },
      stop: () => {
        this.topic.unsubscribe(this.internalListener!);
        this.removeRosHealthHooks();
      },
    };
    this.stream = this.hasMemory
      ? xs.createWithMemory(this.producer)
      : xs.create(this.producer);
    this.isStreamLive = true;

    this.rosConnectionHook = () => {
      if (this.isStreamLive) {
        return;
      }
      this.stream = this.hasMemory
        ? xs.createWithMemory(this.producer)
        : xs.create(this.producer);
      this.isStreamLive = true;
      this.listeners.forEach(listener => {
        this.stream.addListener(listener);
      });
    };
    this.ros.on('connection', this.rosConnectionHook);
  }
github staltz / manyverse / src / frontend / drivers / ssb.ts View on Github external
),
    );

    this.selfReplies$ = this.ssb$.map(ssb => (opts?: any) =>
      pull(
        ssb.createUserStream({id: ssb.id, ...opts}),
        pull.filter(isReplyPostMsg),
        pull.asyncMap(mutateMsgWithLiveExtras(ssb)),
      ),
    );

    this.publishHook$ = this.ssb$
      .map(ssb => ssb.hooks.publishStream())
      .flatten();

    this.acceptInviteResponse$ = xs.create();
    this.acceptDhtInviteResponse$ = xs.create();

    this.peers$ = this.ssb$
      .map(ssb =>
        xsFromPullStream>(ssb.conn.peers())
          .map(peers =>
            backoff(1e3, 2, 60e3)
              .startWith(0)
              .map(() => {
                for (const [, data] of peers) {
                  if (data.key) ssb.cachedAbout.invalidate(data.key);
                }
                return peers;
              }),
          )
          .flatten()
github staltz / manyverse / src / frontend / drivers / ssb.ts View on Github external
);

    this.selfReplies$ = this.ssb$.map(ssb => (opts?: any) =>
      pull(
        ssb.createUserStream({id: ssb.id, ...opts}),
        pull.filter(isReplyPostMsg),
        pull.asyncMap(mutateMsgWithLiveExtras(ssb)),
      ),
    );

    this.publishHook$ = this.ssb$
      .map(ssb => ssb.hooks.publishStream())
      .flatten();

    this.acceptInviteResponse$ = xs.create();
    this.acceptDhtInviteResponse$ = xs.create();

    this.peers$ = this.ssb$
      .map(ssb =>
        xsFromPullStream>(ssb.conn.peers())
          .map(peers =>
            backoff(1e3, 2, 60e3)
              .startWith(0)
              .map(() => {
                for (const [, data] of peers) {
                  if (data.key) ssb.cachedAbout.invalidate(data.key);
                }
                return peers;
              }),
          )
          .flatten()
          .map(peersArr =>