generator icon indicating copy to clipboard operation
generator copied to clipboard

Lean Clients

Open 4x4notfound opened this issue 3 years ago • 0 comments

Generator should support leaner clients by specifying transport class upfront

Describe the solution you'd like Within components subset of client.ts to eliminate switch statements and import only the transport requested.

Describe alternatives you've considered None

Additional context Here is the switch statement and import to be removed

import { RequestManager, PostMessageWindowTransport, PostMessageIframeTransport, WebSocketTransport, HTTPTransport, HTTPTransportOptions, Transport, Client, JSONRPCError } from "@open-rpc/client-js";


switch (type) {
      case 'injected':
        this.transport = injected;
        break;
      case 'http':
      case 'https':
        this.transport = new HTTPTransport((protocol || type) + "://" + host + ":" + port + path );
        break;
      case 'websocket':
        this.transport = new WebSocketTransport((protocol || "ws://") + host + ":" + port + path);
        break;
      case 'postmessageiframe':
        this.transport = new PostMessageIframeTransport(protocol + "://" + host + ":" + port + path);
        break;
      case 'postmessagewindow':
        this.transport = new PostMessageWindowTransport(protocol + "://" + host + ":" + port + path);
        break;
      default:
        throw new Error("unsupported transport");
        break;
    }
    ```

4x4notfound avatar Dec 17 '22 14:12 4x4notfound