How to use the wonka.switchMap function in wonka

To help you get started, we’ve selected a few wonka 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 FormidableLabs / urql / src / hooks / useSubscription.ts View on Github external
subscription$$ =>
      pipe(
        subscription$$,
        switchMap(subscription$ => {
          if (!subscription$) return fromValue({ fetching: false });

          return concat([
            // Initially set fetching to true
            fromValue({ fetching: true }),
            pipe(
              subscription$,
              map(({ stale, data, error, extensions }) => ({
                fetching: true,
                stale: !!stale,
                data,
                error,
                extensions,
              }))
            ),
            // When the source proactively closes, fetching is set to false
github FormidableLabs / urql / src / hooks / useQuery.ts View on Github external
query$$ =>
      pipe(
        query$$,
        switchMap(query$ => {
          if (!query$) return fromValue({ fetching: false });

          return concat([
            // Initially set fetching to true
            fromValue({ fetching: true }),
            pipe(
              query$,
              map(({ stale, data, error, extensions }) => ({
                fetching: false,
                stale: !!stale,
                data,
                error,
                extensions,
              }))
            ),
            // When the source proactively closes, fetching is set to false
github FormidableLabs / urql / src / client.ts View on Github external
executeQuery = <data>(
    query: GraphQLRequest,
    opts?: Partial
  ): Source&gt; =&gt; {
    const operation = this.createRequestOperation('query', query, opts);
    const response$ = this.executeRequestOperation(operation);
    const { pollInterval } = operation.context;

    if (pollInterval) {
      return pipe(
        merge([fromValue(0), interval(pollInterval)]),
        switchMap(() =&gt; response$)
      );
    }

    return response$;
  };
</data>