Skip to content

Lean Clients #701

@4x4notfound

Description

@4x4notfound

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;
    }
    ```

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions