How to use wonka - 10 common examples

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 / exchanges / debug.ts View on Github external
return ops$ =>
      pipe(
        ops$,
        // eslint-disable-next-line no-console
        tap(op => console.log('[Exchange debug]: Incoming operation: ', op)),
        forward,
        tap(result =>
          // eslint-disable-next-line no-console
          console.log('[Exchange debug]: Completed operation: ', result)
        )
      );
  }
github FormidableLabs / urql / src / exchanges / debug.ts View on Github external
return ops$ =>
      pipe(
        ops$,
        // eslint-disable-next-line no-console
        tap(op => console.log('[Exchange debug]: Incoming operation: ', op)),
        forward,
        tap(result =>
          // eslint-disable-next-line no-console
          console.log('[Exchange debug]: Completed operation: ', result)
        )
      );
  }
github FormidableLabs / urql / src / exchanges / ssr.ts View on Github external
const ssr: SSRExchange = ({ client, forward }) => ops$ => {
    // params.isClient tells us whether we're on the client-side
    // By default we assume that we're on the client if suspense-mode is disabled
    const isClient =
      params && typeof params.isClient === 'boolean'
        ? !!params.isClient
        : !client.suspense;

    const sharedOps$ = share(ops$);

    let forwardedOps$ = pipe(
      sharedOps$,
      filter(op => !isCached(op)),
      forward
    );

    // NOTE: Since below we might delete the cached entry after accessing
    // it once, cachedOps$ needs to be merged after forwardedOps$
    let cachedOps$ = pipe(
      sharedOps$,
      filter(op => isCached(op)),
      map(op => {
        const serialized = data[op.key];
        return deserializeResult(op, serialized);
      })
    );
github FormidableLabs / urql / src / client.ts View on Github external
executeRequestOperation(operation: Operation): Source {
    const { key, operationName } = operation;
    const operationResults$ = pipe(
      this.results$,
      filter(res => res.operation.key === key)
    );

    if (operationName === 'mutation') {
      // A mutation is always limited to just a single result and is never shared
      return pipe(
        operationResults$,
        onStart(() => this.dispatchOperation(operation)),
        take(1)
      );
    }

    const teardown$ = pipe(
      this.operations$,
      filter(op => op.operationName === 'teardown' && op.key === key)
github FormidableLabs / urql / src / client.ts View on Github external
if (operationName === 'mutation') {
      // A mutation is always limited to just a single result and is never shared
      return pipe(
        operationResults$,
        onStart(() => this.dispatchOperation(operation)),
        take(1)
      );
    }

    const teardown$ = pipe(
      this.operations$,
      filter(op => op.operationName === 'teardown' && op.key === key)
    );

    const result$ = pipe(
      operationResults$,
      takeUntil(teardown$),
      onStart(() => this.onOperationStart(operation)),
      onEnd(() => this.onOperationEnd(operation))
    );

    return operation.context.suspense !== false &&
      this.suspense &&
      operationName === 'query'
      ? toSuspenseSource(result$)
      : result$;
  }
github FormidableLabs / urql / src / client.ts View on Github external
executeRequestOperation(operation: Operation): Source {
    const { key, operationName } = operation;
    const operationResults$ = pipe(
      this.results$,
      filter(res => res.operation.key === key)
    );

    if (operationName === 'mutation') {
      // A mutation is always limited to just a single result and is never shared
      return pipe(
        operationResults$,
        onStart(() => this.dispatchOperation(operation)),
        take(1)
      );
    }

    const teardown$ = pipe(
      this.operations$,
      filter(op => op.operationName === 'teardown' && op.key === key)
    );

    const result$ = pipe(
      operationResults$,
      takeUntil(teardown$),
      onStart(() => this.onOperationStart(operation)),
      onEnd(() => this.onOperationEnd(operation))
github FormidableLabs / urql / src / client.ts View on Github external
const { key, operationName } = operation;
    const operationResults$ = pipe(
      this.results$,
      filter(res => res.operation.key === key)
    );

    if (operationName === 'mutation') {
      // A mutation is always limited to just a single result and is never shared
      return pipe(
        operationResults$,
        onStart(() => this.dispatchOperation(operation)),
        take(1)
      );
    }

    const teardown$ = pipe(
      this.operations$,
      filter(op => op.operationName === 'teardown' && op.key === key)
    );

    const result$ = pipe(
      operationResults$,
      takeUntil(teardown$),
      onStart(() => this.onOperationStart(operation)),
      onEnd(() => this.onOperationEnd(operation))
    );

    return operation.context.suspense !== false &&
      this.suspense &&
      operationName === 'query'
      ? toSuspenseSource(result$)
      : result$;
github FormidableLabs / urql / src / exchanges / ssr.ts View on Github external
const isClient =
      params && typeof params.isClient === 'boolean'
        ? !!params.isClient
        : !client.suspense;

    const sharedOps$ = share(ops$);

    let forwardedOps$ = pipe(
      sharedOps$,
      filter(op => !isCached(op)),
      forward
    );

    // NOTE: Since below we might delete the cached entry after accessing
    // it once, cachedOps$ needs to be merged after forwardedOps$
    let cachedOps$ = pipe(
      sharedOps$,
      filter(op => isCached(op)),
      map(op => {
        const serialized = data[op.key];
        return deserializeResult(op, serialized);
      })
    );

    if (!isClient) {
      // On the server we cache results in the cache as they're resolved
      forwardedOps$ = pipe(
        forwardedOps$,
        tap((result: OperationResult) => {
          const { operation } = result;
          if (!shouldSkip(operation)) {
            const serialized = serializeResult(result);
github FormidableLabs / urql / src / hooks / useSubscription.ts View on Github external
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
            fromValue({ fetching: false }),
          ]);
        }),
        // The individual partial results are merged into each previous result
github FormidableLabs / urql / src / hooks / useQuery.ts View on Github external
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
            fromValue({ fetching: false }),
          ]);
        }),
        // The individual partial results are merged into each previous result