interfaces.IDCreatable

Like interfaces.DepsCreatable except the first argument to __init__ or __defer_init__ is enforced to be the id.
Implements:
See:

Classes

IDCreatable

Members

static __store :Map

The storage object that maps string IDs to instances. This map is shared between all IDCreatables of the same variant.

id :string

The unique ID of this IDCreatable. By default, interfaces.IDCreatable.__new__ given an existing ID on the same variant will return a cached, previously created instance of the same ID.
Default Value:
  • nanotime._str

Methods

static __new__(id, …opts) → {interfaces.IDCreatable|*}

Creates an instance, attaching dependencies as the first argument, followed by the id, then user specified arguments. The instance is saved by ID to a storage object found on Classname.__store. If the object previously exists in storage, it will be re-initialized. If you do not want this behavior, do not call this class's create function and/or manually check for the existence of the object by ID.
Parameters:
Name Type Attributes Description
id string The ID of this instance. Enforced to be a string.
opts * <repeatable>
Options passed to the constructor.
Throws:
Throws an error if the ID given is not a string.
Type
Error
Returns:
interfaces.IDCreatable | * - The instance.
See:

static isIDCreatable(obj) → {boolean}

Checks if the given object is an IDCreatable via Symbol.hasInstance as well as with the isIDCreatable symbol. Use this method if you have an external check on the species, since this[Symbol.species] may be different for every IDCreatable variant.
Parameters:
Name Type Description
obj Object The object to check.
Throws:
Throws an error if obj is not an object (due to Reflect.has being called on it).
Type
Error
Returns:
boolean - Whether the specified object is an IDCreatable.

static super_create(id, …opts) → {interfaces.IDCreatable|*}

Passthrough to interfaces.DepsCreatable.create. Used to specify custom create logic that bypasses that of interfaces.IDCreatable.__new__
Parameters:
Name Type Attributes Description
id string The ID of this instance. Enforced to be a string.
opts * <repeatable>
Options passed to DepsCreatable's create function..
Throws:
Throws an error if the ID given is not a string.
Type
Error
Returns:
interfaces.IDCreatable | * - The instance.
See:

abstract __init__(idopt) → {interfaces.IDCreatable}

Convenience IDCreatable method that sets the first argument as the id of the instance. Can be called through simply super.__init__ where applicable for consistency. To "undo", calling delete this.id works.
Parameters:
Name Type Attributes Default Description
id string <optional>
nanotime._str The ID of this instance.
Returns:
interfaces.IDCreatable - The instance.
Implements:
See: