How to use the xstream.periodic 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 flow-typed / flow-typed / definitions / npm / xstream_v7.x.x / test_xstream.js View on Github external
listener.complete();
  },
  stop: console.log
};

const create: Stream = xs.create(producer);
const createWithMemory: MemoryStream = xs.createWithMemory(producer);
const never: Stream<*> = xs.never();
const empty: Stream<*> = xs.empty();
const _throw: Stream<*> = xs.throw(new Error(123));
const from1: Stream = xs.from([1]);
const from2: Stream = xs.from(Promise.resolve(1));
const of: Stream = xs.of(1);
const fromArray: Stream = xs.fromArray([1,2,3]);
const fromPromise: Stream = xs.from(Promise.resolve(1));
const periodic: Stream = xs.periodic(123);
const merge: Stream = xs.merge(of, of);
const merge2: Stream = xs.merge(of, of, of, of);
const combine: Stream = xs.combine(of, of);
const combine2: Stream = xs.combine(of, of, of, of);

const listener = {
  next: console.log,
  error: console.error,
  complete: console.log
};

of.addListener(listener);
of.removeListener(listener);

const subscription: Subscription = of.subscribe({
  next: x => console.log(x),
github fanduel-oss / refract / examples / visit-time / xstream / src / index.js View on Github external
onlineAndVisible =>
                onlineAndVisible
                    ? xs
                          .periodic(10)
                          .mapTo({
                              type: 'TICK'
                          })
                          .startWith({ type: 'RESUME' })
                    : xs.of({ type: 'PAUSE' })
        )
github cyclejs / cyclejs / native / example / common.js View on Github external
export function main({Screen, HTTP}) {
  let requestStars$ = xs.of({url: REPO_URL, category: 'stars'});
  let requestEvents$ = xs.of({url: COLL_URL, category: 'events'});
  let request$ = xs.merge(requestStars$, requestEvents$);
  let toast$ = xs.periodic(2000).take(1)
    .mapTo({message: 'Hello world!', type: 'show', duration: 1000});
  return {
    Screen: model(intent(Screen, HTTP)).map(view),
    Toast: toast$,
    HTTP: request$,
  };
}
github staltz / manyverse / src / frontend / screens / central / connections-tab / intent.ts View on Github external
.map(isTabVisible =>
        isTabVisible
          ? concat(xs.of(0), xs.periodic(2000).take(2), xs.periodic(6000))
          : xs.never(),
      )
github cyclejs / cyclejs / examples / advanced-list / src / ticker.js View on Github external
function model(action$, givenColor$) {
  const stop$ = action$.filter(a => a.type === 'stop');
  const x$ = xs.periodic(50).startWith(0).endWhen(stop$);
  const y$ = xs.periodic(100).startWith(0).endWhen(stop$);
  const color$ = xs.merge(
    givenColor$.endWhen(stop$),
    stop$.mapTo('#FF0000')
  );
  return xs.combine((x, y, color) => ({x, y, color}), x$, y$, color$);
}
github tryanzu / frontend / src / components / chat / intent.js View on Github external
list =>
                list.length > 0
                    ? xs
                          .periodic(12000)
                          .filter(x => x > 0)
                          .startWith(0)
                          .map(x => x % list.length)
                          .map(x => list[x])
                    : xs.empty()
        )
github cyclejs / cyclejs / examples / advanced-list / src / ticker.js View on Github external
function model(action$, givenColor$) {
  const stop$ = action$.filter(a => a.type === 'stop');
  const x$ = xs.periodic(50).startWith(0).endWhen(stop$);
  const y$ = xs.periodic(100).startWith(0).endWhen(stop$);
  const color$ = xs.merge(
    givenColor$.endWhen(stop$),
    stop$.mapTo('#FF0000')
  );
  return xs.combine((x, y, color) => ({x, y, color}), x$, y$, color$);
}
github qiscus / qiscus-sdk-web-core / src / adapters / realtime.ts View on Github external
export default function getRealtimeAdapter(
  http: Derivable,
  messageAdapter: Derivable,
  roomAdapter: Derivable,
  syncInterval: Derivable,
  brokerUrl: Derivable,
  shouldSync: Derivable,
  isLogin: Derivable,
  token: Derivable
): IQRealtimeAdapter {
  const isMqttConnected = atom(false);
  const sync = getSyncAdapter(http, messageAdapter, roomAdapter, token);
  const mqtt = getMqttAdapter(messageAdapter, brokerUrl);

  xs.periodic(syncInterval.get())
    .filter(() => isLogin.get())
    .filter(() => !isMqttConnected.get() || shouldSync.get())
    .subscribe({
      next() {
        sync.synchronize();
        sync.synchronizeEvent();
      }
    });

  mqtt.onMqttConnected(() => isMqttConnected.set(true));

  return {
    get mqtt() {
      return mqtt;
    },
    onMessageDeleted(callback: Callback): Subscription {
github Nitive / illuminati / src / app.tsx View on Github external
.fold(state => !state, false)

  const buttonText$ = visible$.map(state => state ? 'hide' : 'show')
  const highlighted$ = xs.periodic(1000).fold(highlighted => !highlighted, true)
  const buttonClass$ = highlighted$.map(highlighted => joinClasses('inc', highlighted && 'highlighted'))

  const arrOfComponents = [
    <div>div</div>,
    'string',
    <br>,
    'stream: ',
    count$,
  ]

  const range = L.range(15)
  const keys$ = xs.periodic(5000)
    .startWith(0)
    .map(() =&gt; range.filter(() =&gt; Math.random() &gt; .5))

  interface Item {
    color: Stream,
    count: number,
    index: number,
  }

  interface State {
    items: Item[],
  }

  const initialState: State = {
    items: Array(15)
      .fill(undefined)
github staltz / dat-installer / src / frontend / screens / central / index.ts View on Github external
function httpRequests(start$: Stream): Stream {
  const pingReq$ = xs
    .periodic(300)
    .startWith(0)
    .endWhen(start$)
    .mapTo({ category: "ping", url: "/ping" });

  const setStoragePathReq$ = start$.mapTo({
    category: "setStoragePath",
    url: "/setStoragePath",
    method: "POST",
    send: { path: RNFS.ExternalStorageDirectoryPath + "/DatInstaller" },
  });

  const latestReq$ = start$
    .map(() =&gt; xs.periodic(2000).startWith(null as any))
    .flatten()
    .mapTo({ category: "latest", url: "/latest" });