Skip to content

Should Network.create() take a specific type as its parameter? #1126

@haxwell

Description

@haxwell

In network.js..

static create(options) {
    if (typeof options === 'string')
      options = networks[options];

    assert(options, 'Unknown network.');

    if (Network[options.type])               //  <<< Line 136
      return Network[options.type];

    const network = new Network(options);

    Network[network.type] = network;

    if (!Network.primary)
      Network.primary = network;

    return network;
  }

This method will take a string, or a set of key-value pairs it uses as options. Still, it is possible to send an empty object, or other not-specifically-handled type, and it would cause an exception on line 136. Should we create a type for these options, and use instanceof like, for example the get() method a little further down in network.js...

  static get(type) {
    if (!type) {
      assert(Network.primary, 'No default network.');
      return Network.primary;
    }

    if (type instanceof Network)    //    Like this here..
      return type;

    if (typeof type === 'string')
      return Network.create(type);

    throw new Error('Unknown network.');
  }

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