How to use the xstream/extra/delay 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 reducers$ = xs.merge(
        xs.of(state => merge(LENSED_STATE, state)),
        postR$,
        postLoadingR$,
        commentFocusR$,
        votingR$,
        voteFailR$,
        voteFailDismissR$,
        replyToR$,

        // Incoming vote effects.
        actions.vote$
            .filter(res => 'action' in res)
            .compose(sampleCombine(actions.voting$))
            .compose(delay(500))
            .map(([status, vote]) => state => {
                const value = status.action == 'create' ? 1 : -1;

                return update(state, {
                    voting: false,
                    comments: {
                        map: {
                            [vote.id]: {
                                votes: {
                                    up:
                                        state.own.comments.map[vote.id].votes
                                            .up +
                                        (vote.intent == 'up' ? value : 0),
                                    down:
                                        state.own.comments.map[vote.id].votes
                                            .down +
github cyclejs-community / xstream-boilerplate / test / util / index.js View on Github external
it('should merge multiple objects of streams together', (done) => {
      const a = {a: xs.of(1)}
      const b = {a: xs.of(2).compose(delay(10))}

      const expected = [1, 2]

      mergeFlatten('a', [a, b])
        .addListener({
          next: x => {
            assert(x === expected.shift())
          },
          error: done,
          complete: () => {
            assert(expected.length === 0)
            done()
          }
        })
    })
github staltz / matrixmultiplication.xyz / src / Calculator / view / tweens.ts View on Github external
state.measurements.matrixBHeight * 0.5;
      const yLastComb = yLift -
        padding -
        styles.matrixBracketWidth * 2 -
        state.measurements.rowHeight * (state.step - 2);
      const yOutside = yLastComb -
        state.measurements.rowHeight -
        padding * 4;
      return concat(
        tween({ from: yLastComb, to: yOutside, duration, ease }).map(y => `
          translateX(${-xMove}px)
          translateY(${-y}px)
          rotateZ(-90deg)
        `),
        xs.of('translateX(0px) translateY(0px) rotateZ(0deg)')
          .compose(delay(timeToReset * 0.9)),
      );
    })
    .flatten();
github staltz / matrixmultiplication.xyz / src / Calculator / timers.ts View on Github external
s1.step === s2.step && s1.canInteract === s2.canInteract
    ));

  const allowContinueFromStartMultiply$ = stateChange$
    .filter(state => state.step === 1 && !state.canInteract)
    .compose(delay(styles.step1Duration1 + styles.step1Duration2))
    .mapTo(null);

  const allowContinueFromNextComb$ = stateChange$
    .filter(state => isInCombStep(state) && !state.canInteract)
    .compose(delay(styles.nextCombDuration))
    .mapTo(null);

  const allowContinueFromEnd$ = stateChange$
    .filter(state => state.step === lastCombStep(state) + 1 && !state.canInteract)
    .compose(delay(styles.finalResultDuration))
    .mapTo(null);

  return xs.merge(
    allowContinueFromStartMultiply$,
    allowContinueFromNextComb$,
    allowContinueFromEnd$,
  );
}
github staltz / matrixmultiplication.xyz / src / Calculator / timers.ts View on Github external
export default function timers(state$: Stream): Stream {
  const stateChange$ = state$
    .compose(dropRepeats((s1: State, s2: State) =>
      s1.step === s2.step && s1.canInteract === s2.canInteract
    ));

  const allowContinueFromStartMultiply$ = stateChange$
    .filter(state => state.step === 1 && !state.canInteract)
    .compose(delay(styles.step1Duration1 + styles.step1Duration2))
    .mapTo(null);

  const allowContinueFromNextComb$ = stateChange$
    .filter(state => isInCombStep(state) && !state.canInteract)
    .compose(delay(styles.nextCombDuration))
    .mapTo(null);

  const allowContinueFromEnd$ = stateChange$
    .filter(state => state.step === lastCombStep(state) + 1 && !state.canInteract)
    .compose(delay(styles.finalResultDuration))
    .mapTo(null);

  return xs.merge(
    allowContinueFromStartMultiply$,
    allowContinueFromNextComb$,
    allowContinueFromEnd$,
github staltz / matrixmultiplication.xyz / src / Calculator / timers.ts View on Github external
export default function timers(state$: Stream): Stream {
  const stateChange$ = state$
    .compose(dropRepeats((s1: State, s2: State) =>
      s1.step === s2.step && s1.canInteract === s2.canInteract
    ));

  const allowContinueFromStartMultiply$ = stateChange$
    .filter(state => state.step === 1 && !state.canInteract)
    .compose(delay(styles.step1Duration1 + styles.step1Duration2))
    .mapTo(null);

  const allowContinueFromNextComb$ = stateChange$
    .filter(state => isInCombStep(state) && !state.canInteract)
    .compose(delay(styles.nextCombDuration))
    .mapTo(null);

  const allowContinueFromEnd$ = stateChange$
    .filter(state => state.step === lastCombStep(state) + 1 && !state.canInteract)
    .compose(delay(styles.finalResultDuration))
    .mapTo(null);

  return xs.merge(
    allowContinueFromStartMultiply$,
    allowContinueFromNextComb$,
    allowContinueFromEnd$,
  );
}
github cyclejs / collection / examples / taskrunner / app.js View on Github external
function Task ({DOM, props$}) {
  const delete$ = DOM
    .select('.delete')
    .events('click');

  const changeText = DOM.select('.change-text');
  const changeText$ = xs.merge(
    changeText.events('keydown')
      .filter(event => event.code === 'Enter'),
    changeText.events('blur')
  ).map(event => event.target.value);

  const editing$ = xs.merge(
    DOM.select('.text').events('click').mapTo(true),
    changeText$.compose(delay()).mapTo(false)
  ).startWith(false);

  const edit$ = editing$.map(editing => changeText$.filter(() => editing)).flatten();

  return {
    DOM: xs.combine(props$, editing$).map(taskView),
    complete$: props$.map(({status}) => status === 'complete'),
    delete$,
    edit$,
    HTTP: props$.map(({id}) => ({
      url: `/tasks/${id}`
    }))
  };
}
github staltz / matrixmultiplication.xyz / src / Calculator / measure.ts View on Github external
}
      const measurements: Measurements = {
        matrixAHeight: matrixAElem.clientHeight,
        matrixBWidth: matrixBElem.clientWidth,
        matrixBHeight: matrixBElem.clientHeight,
        rowHeight: someRow.clientHeight,
      };
      return measurements;
    })
    .filter(isNotNull)
    .compose(dropRepeats((m1: Measurements, m2: Measurements) =>
      m1.matrixAHeight === m2.matrixAHeight &&
      m1.matrixBHeight === m2.matrixBHeight &&
      m1.matrixBWidth === m2.matrixBWidth
    ))
    .compose(delay(16));
}
github cyclejs-community / cyclejs-sortable / src / makeSortable.ts View on Github external
.map(ev =>
                xs
                    .of(ev)
                    .compose>(delay(options.selectionDelay))
                    .endWhen(xs.merge(up$, move$))
            )
github staltz / manyverse / src / frontend / screens / compose / navigation.ts View on Github external
export default function navigation(actions: Actions): Stream {
  const goBack$ = actions.exitOfAnyKind$
    .compose(delay(100))
    .map(() => ({type: 'dismissOverlay'} as Command));

  return goBack$;
}