How to use the xstream/extra/sampleCombine 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 tryanzu / frontend / src / components / post / model.js View on Github external
),
    });
    const lastSentReply$ = actions.sentReply$
        .filter(res => 'id' in res)
        .map(res => res.id)
        .startWith(false);

    /**
     * Http write effects, including:
     * - votes requests
     * - comments requests
     */
    const http$ = xs.merge(
        // New votes
        actions.voting$
            .compose(sampleCombine(actions.authToken$))
            .map(([{ type, intent, id }, withAuth]) => ({
                method: 'POST',
                type: 'application/json',
                url: `${Anzu.layer}vote/${type}/${id}`,
                category: 'vote',
                send: { direction: intent },
                headers: withAuth({}),
            })),

        // Replies sent
        actions.reply$
            .compose(sampleCombine(actions.replyContent$, actions.authToken$))
            .map(([{ type, id }, content, withAuth]) => ({
                method: 'POST',
                type: 'application/json',
                url: `${Anzu.layer}comments/${id}?type=${type}`,
github kylecordes / cycle-example-1 / src / 06-timer / timer.ts View on Github external
export function Timer(sources: Sources) {
  // Initialze if used alone - use parent provided state is present
  const defaultReducer$ = xs.of(prev => prev || { running: false });

  const i$ = sources.time.periodic(100)
    .map(x => x + 1)
    .startWith(0)
    .remember();

  const start$ = sources.DOM.select('.start').events('click')
    .compose(sampleCombine(i$))
    .map(eventI => state => ({ ...state, running: true, x: eventI[1] - state.x }));

  const stop$ = sources.DOM.select('.stop').events('click')
    .compose(sampleCombine(i$))
    .map(eventI => state => ({ ...state, running: false, x: eventI[1] - state.x }));

  const reset$ = sources.DOM.select('.reset').events('click')
    .mapTo(state => ({ ...state, running: false, x: 0 }));

  return {
    DOM: view(sources.onion.state$, i$),
    onion: xs.merge(defaultReducer$, start$, stop$, reset$)
  };
}
github Widdershin / tricycle / src / scratchpad.js View on Github external
}
      },
      error (err) {
        console.error(err);
      },
      complete () {}
    });

  const restartEnabled$ = DOM.select('.instant-checkbox').events('change')
    .map(ev => ev.target.checked)
    .startWith(true);

  xs.merge(props, code$)
    .compose(debounce(300))
    .map(transformES6(error$))
    .compose(sampleCombine(restartEnabled$))
    .addListener({
      next ([{code}, restartEnabled]) {
        runOrRestart(code, restartEnabled)
      },
      error (err) {
        console.error(err);
      },
      complete () {}
    })

  function runOrRestart(code, restartEnabled) {
    if (sources) {
      sources.dispose();
    }

    if (sinks) {
github staltz / dat-installer / src / frontend / screens / addition / index.ts View on Github external
export default function addition(sources: Sources): Sinks {
  const state$ = sources.onion.state$;
  const actions = intent(sources.screen);

  const addDat$ = actions.submit$
    .compose(sampleCombine(state$))
    .map(([_, state]) => state.textInput.startsWith('dat://')
      ? state.textInput.substr(6)
      : state.textInput
    );

  const request$ = addDat$.map(datHash => ({
    url: "/datSync",
    method: "POST",
    send: { datKey: datHash },
  }));

  const dismissThisScreen$ = addDat$.mapTo({
    type: "dismissModal",
  } as DismissModalCommand);

  const reducer$ = model(actions);
github staltz / manyverse / src / frontend / screens / central / index.ts View on Github external
export function central(sources: Sources): Sinks {
  const topBarSinks: TBSinks = isolate(topBar, {
    '*': 'topBar',
    state: topBarLens,
  })(sources);

  const actions = intent(sources.screen);

  const scrollToTop$ = actions.changeTab$
    .compose(sampleCombine(sources.state.stream))
    .filter(([i, state]) => state.currentTab === 0 && i === 0)
    .mapTo(null);

  const fabPress$: Stream = sources.screen
    .select('fab')
    .events('pressItem');

  const publicTabSinks = isolate(publicTab, {
    state: publicTabLens,
    '*': 'publicTab',
  })({...sources, scrollToTop: scrollToTop$, fab: fabPress$}) as PublicTabSinks;

  const connectionsTabSinks = isolate(connectionsTab, {
    state: connectionsTabLens,
    '*': 'connectionsTab',
  })({...sources, fab: fabPress$}) as ConnectionsTabSinks;
github cyclejs-community / one-fits-all / template / src / components / speaker.tsx View on Github external
function speech(speech$: Stream, state$: Stream): Stream {
    return speech$
        .compose(sampleCombine(state$))
        .map(([_, s]: [any, State]) => s.text);
}
github staltz / manyverse / src / frontend / screens / central / public-tab / navigation.ts View on Github external
({
        type: 'push',
        layout: {
          component: {
            name: Screens.Profile,
            passProps: {
              selfFeedId: state.selfFeedId,
              feedId: ev.authorFeedId,
            },
            options: profileScreenNavOptions,
          },
        },
      } as Command),
  );

  const toThread$ = actions.goToThread$.compose(sampleCombine(state$)).map(
    ([ev, state]) =>
      ({
        type: 'push',
        layout: {
          component: {
            name: Screens.Thread,
            passProps: {
              selfFeedId: state.selfFeedId,
              rootMsgId: ev.rootMsgId,
              replyToMsgId: ev.replyToMsgId,
            },
            options: threadScreenNavOptions,
          },
        },
      } as Command),
  );
github tryanzu / frontend / src / components / chat / model.js View on Github external
...state,
        message: message.sent ? '' : message.payload,
    }));
    const onlineR$ = actions.online$.map(list => state => ({
        ...state,
        online: list,
    }));

    /**
     * Transform sent messages to packed list of actual commands.
     *
     * @type {Stream<u>|Stream}
     */
    const sent$ = actions.msg$
        .filter(message =&gt; message.sent)
        .compose(sampleCombine(user$))
        .map(([msg, user]) =&gt; message(cmessage(user, msg, new Date())));

    const sentLists$ = sent$.map(message =&gt; list(message));
    const messagesR$ = xs
        .merge(actions.messages$, sentLists$)
        .map(packed =&gt; state =&gt; {
            const channel = packed.channel || false;
            let list =
                channel == false ||
                state.channel == channel ||
                channel === 'log'
                    ? state.list.concat(packed.list)
                    : state.list;

            if (
                (channel == false ||</u>
github staltz / manyverse / src / frontend / screens / compose / intent.ts View on Github external
publishReply$,

    togglePreview$: topBarPreviewToggle$,

    updatePostText$: reactSource
      .select('composeInput')
      .events('changeText') as Stream,

    updateMentionQuery$: reactSource
      .select('mentionInput')
      .events('changeText') as Stream,

    updateSelection$,

    suggestMention$: updateSelection$
      .compose(sampleCombine(state$))
      .map(
        ([selection, state]) =&gt;
          [parseMention(state.postText, selection), selection] as [
            ReturnType,
            typeof selection,
          ],
      ),

    chooseMention$: reactSource
      .select('suggestions')
      .events('pressAccount') as Stream&lt;{id: FeedId; name: string}&gt;,

    cancelMention$: reactSource.select('mentions-cancel').events('press'),

    openContentWarning$: reactSource
      .select('content-warning')
github staltz / manyverse / src / frontend / screens / accounts / index.ts View on Github external
function navigation(actions: Actions, state$: Stream) {
  const pop$ = actions.goBack$.mapTo({
    type: 'pop',
  } as PopCommand);

  const toProfile$ = actions.goToProfile$.compose(sampleCombine(state$)).map(
    ([ev, state]) =&gt;
      ({
        type: 'push',
        layout: {
          component: {
            name: Screens.Profile,
            passProps: {
              selfFeedId: state.selfFeedId,
              feedId: ev.id,
            },
            options: profileScreenNavOptions,
          },
        },
      } as Command),
  );