How to use the xstream.merge 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 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$
      .fold((collection, reducer) => reducer(collection), emptyCollection)
      .map(collection => collection.asArray());

    const remove$ = Collection.merge(collection$, item => item._remove$, true);
    removeProxy$.imitate(remove$);

    return adapt(collection$);
  }
github staltz / manyverse / src / frontend / screens / thread / model.ts View on Github external
)
    .flatten()
    .map(
      newMsg =>
        function addSelfRepliesReducer(prev: State): State {
          return {
            ...prev,
            thread: {
              messages: prev.thread.messages.concat([newMsg]),
              full: true,
            },
          };
        },
    );

  return xs.merge(
    propsReducer$,
    setThreadReducer$,
    keyboardAppearedReducer$,
    keyboardDisappearedReducer$,
    updateReplyTextReducer$,
    publishReplyReducers$,
    aboutReducer$,
    emptyReplyTextReducer$,
    loadReplyDraftReducer$,
    addSelfRepliesReducer$,
  );
}
github staltz / matrixmultiplication.xyz / src / Calculator / timers.ts View on Github external
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 tryanzu / frontend / src / components / modal / signup / model.js View on Github external
username,
            password,
        })
    );
    const sentR$ = actions.sent$.map(sent => state => ({
        ...state,
        resolving: sent,
    }));
    const tokenR$ = actions.token$.map(res => state => ({
        ...state,
        resolving: false,
        error: res instanceof Error ? res : false,
        done: !(res instanceof Error),
    }));

    const state$ = xs
        .merge(fieldsR$, sentR$, tokenR$)
        .fold((state, action) => action(state), DEFAULT_STATE);

    return {
        state$,
        token$,
        HTTP: requestToken$,
    };
}
github sarimarton / powercycle / src / powercycle.js View on Github external
  mergeFn: streams => xs.merge(...streams)
}
github staltz / manyverse / src / frontend / screens / accounts / index.ts View on Github external
function intent(
  navSource: NavSource,
  reactSource: ReactSource,
  back$: Stream,
) {
  return {
    goBack$: xs.merge(navSource.backPress(), back$),

    goToProfile$: reactSource.select('accounts').events('pressAccount'),
  };
}
github sarimarton / powercycle / src / util.js View on Github external
const request$ = url$.map(url => ({ url, category }))

  const response$ =
    sources.HTTP
      .select(category)
      .map(resp$ => resp$.replaceError(err => xs.of(err)))
      .flatten()

  const content$ =
    response$
      .filter(resp => !(resp instanceof Error))
      .map(resp => JSON.parse(resp.text))
      .remember()

  const isLoading$ = xs.merge(
    request$.mapTo(true),
    response$.mapTo(false)
  ).startWith(false)

  const errorMessage$ =
    response$
      .filter(resp => resp instanceof Error)
      .startWith('')

  return { request$, content$, isLoading$, errorMessage$ }
}
github cyclejs / collection / examples / taskrunner / app.js View on Github external
function itemRequests$ (deleteComplete$, item) {
  const delete$ = xs.merge(
    item.delete$,
    deleteItemIfComplete$(deleteComplete$, item.complete$)
  ).mapTo({
    method: 'DELETE',
    type: 'application/json'
  });

  const edit$ = item.edit$.map(text => ({
    method: 'PATCH',
    type: 'application/json',
    send: {text}
  }));

  const request$ = xs.merge(delete$, edit$);

  return item.HTTP.map(base => request$.map(request => ({
    ...base,
    ...request
  })))
    .flatten();
}
github staltz / manyverse / src / frontend / screens / biography / index.ts View on Github external
export function biography(sources: Sources): Sinks {
  const topBarSinks: TBSinks = topBar(sources);

  const vdom$ = view(sources.state.stream, topBarSinks.screen);

  const command$ = xs
    .merge(sources.navigation.backPress(), topBarSinks.back)
    .mapTo({type: 'pop'} as Command);

  const reducer$ = sources.props.map(
    props =>
      function propsReducer(): State {
        return props;
      },
  );

  return {
    screen: vdom$,
    navigation: command$,
    state: reducer$,
  };
}