How to use the xstream.of 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 Nitive / illuminati / src / dom.ts View on Github external
if (prevNode) {
          node.insertBefore(n, prevNode.nextSibling)
          return
        }

        node.insertBefore(n, node.firstChild)
      }

      createNode(insert, child).nodeP.then(node => {
        childrenNodes[index] = node
      })
    })
    return node
  }

  const visible$ = props.if$ || xs.of(true)
  const createElementWithHooks = createElementSubscriber(insert, visible$)

  return createElementWithHooks({
    async mount(shouldBeVisible, insert) {
      if (shouldBeVisible) {
        return await add(insert)
      }
      return
    },
    async update(shouldBeVisible, node, insert) {
      if (shouldBeVisible) {
        return await add(insert)
      } else {
        // node always exist because dropRepeats() guarantees previous state is false
        // so we can use ! to remove undefined variant from type
        await removeNode(node!)
github tryanzu / frontend / src / components / post / model.js View on Github external
voting: false,
            toasts: state.own.toasts.concat([
                { type: 'error', content: traduceErr(err) },
            ]),
        })
    );

    const voteFailDismissR$ = voteErr$.compose(delay(5000)).map(() => state =>
        update(state, {
            toasts:
                state.own.toasts.length > 0 ? state.own.toasts.slice(1) : [],
        })
    );

    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;
github atomrc / cyclejs-auth0 / tests / AuthenticationWrapper.js View on Github external
it("should re show Auth0 login form", (done) => {
                    const sources = getSources({
                        auth0: { select: () => xs.empty(), tokens$: xs.of(tokens, null) }
                    });

                    const { auth0 } = AuthenticationWrapper(sources);

                    auth0
                        .addListener(getListener({
                            next: action => {
                                expect(action.action).to.be("show")
                                done();
                            }
                        }));
                });
        });
github cyclejs / react / test / conversion.ts View on Github external
sources.react
        .props()
        .drop(1)
        .take(1)
        .addListener({
          next: props => {
            assert.strictEqual(first, true);
            assert.strictEqual(props.name, 'alice');
            assert.strictEqual(props.age, 31);
            done();
          },
        });

      return {
        react: xs.of(
          h('section', [h('div', {}, [h('h1', {}, 'Hello world')])]),
        ),
      };
    }
github atomrc / cyclejs-auth0 / tests / AuthenticationWrapper.js View on Github external
function getSources(overrides) {
    const defaultSources = {
        auth0: { select: () => {}, tokens$: xs.of(null) },
        props: {
            authWrapperParams: {
                Child: () => ({})
            }
        }
    };
    return {
        ...defaultSources,
        ...overrides
    };
}
github usm4n / cycle-hn / src / components / FeedAtom.tsx View on Github external
export const FeedAtom: Component = function(sources: FeedSources): FeedSinks {
    const vdom$ = view(sources.onion.state$);

    const sinks = {
        DOM: vdom$,
        onion: xs.of((state) => state)
    };

    return sinks;
};
github cyclejs / cyclejs / examples / many / src / Item.ts View on Github external
function model(actions: Actions) {
  const initReducer$ = xs.of(function initReducer(prevState: State): State {
    if (prevState) {
      return prevState;
    } else {
      return {color: '#888', width: 200};
    }
  });

  const removeReducer$ = actions.remove$
    .mapTo(function removeReducer(prevState: State): State {
      return undefined;
    });

  const changeWidthReducer$ = actions.changeWidth$
    .map((width: number) => function changeWidthReducer(prevState: State): State {
      return {...prevState, width};
    });
github staltz / manyverse / src / frontend / screens / central / connections-tab / model.ts View on Github external
.map(stagedPeers => {
      const dhtInvites = stagedPeers
        .filter(([_address, data]) => data.type === 'dht')
        .map(noteStorageKeyFor);

      if (dhtInvites.length === 0) {
        const notes: Array<[string, string]> = [];
        return xs.of([stagedPeers, notes]);
      } else {
        return asyncStorageSource
          .multiGet(dhtInvites)
          .map(keyValuePairs => [stagedPeers, keyValuePairs]);
      }
    })
    .flatten()
github shinima / trips-editor / src / interaction / zoom.ts View on Github external
.map(([zoomConfig, { transform: startTransform }, config, viewBox]) => {
      const { rawPos, targetTransform, useTransition } = zoomConfig
      if (useTransition) {
        return transition(250, startTransform, targetTransform, interpolateTransform(viewBox)).map(
          nextTransform =>
            new SetTransformAction(nextTransform, startTransform, rawPos, config.senseRange),
        )
      } else {
        return xs.of(
          new SetTransformAction(targetTransform, startTransform, rawPos, config.senseRange),
        )
      }
    })
    .flatten()