How to use @shopify/rpc - 2 common examples

To help you get started, we’ve selected a few @shopify/rpc 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 Shopify / quilt / packages / web-worker / src / create / worker.ts View on Github external
function createWorker({
    createMessenger = createWorkerMessenger,
  }: CreateWorkerOptions = {}): Endpoint['call'] {
    if (scriptUrl) {
      const endpoint = createEndpoint(createMessenger(scriptUrl));
      const {call: caller} = endpoint;

      workerEndpointCache.set(caller, endpoint);

      return caller as any;
    }

    // The babel plugin that comes with this package actually turns the argument
    // into a string (the public path of the worker script). If it’s a function,
    // it’s because we’re in an environment where we didn’t transform it into a
    // worker. In that case, we can use the fact that we will get access to the
    // real module and pretend to be a worker that way.
    if (typeof script === 'function') {
      return new Proxy(
        {},
        {
github Shopify / quilt / packages / web-worker / src / worker.ts View on Github external
export function expose(api: any) {
  const endpoint = createEndpoint(fromWebWorker(self as any));

  self.addEventListener('message', ({data}: MessageEvent) => {
    if (data == null) {
      return;
    }

    if (data.__replace instanceof MessagePort) {
      endpoint.replace(data.__replace);
      data.__replace.start();
    }
  });

  Reflect.defineProperty(self, 'endpoint', {
    value: endpoint,
  });

@shopify/rpc

Utilities for `postMessage`-based remote procedure calls

MIT
Latest version published 2 years ago

Package Health Score

60 / 100
Full package analysis