Factoryable

Properties

3

Class hierarchy

isFactoryable: Boolean= truereadonly
Identifies an object as an instance of Factoryable class, or subclass thereof.
isFactoryable: Boolean= truereadonlystatic
Identifies an object as an instance of Factoryable class, or subclass thereof.

Other

type: Stringstatic

The (canonical) type name for this class by which instances can be created using the static create() method.

Functions

5
createstatic

Creates an instance from this factory, given the type name or a config object.

ParameterTypeDescription
configString | Object

The type name string or config object.

optionsString | function | Object

Creation options (for details see reconfigure).

Returns: Object
isAstatic

Returns true if the passed instance is of the passed type or of a derived class.

ParameterTypeDescription
instanceObject

The object to test.

typeString

The type to test against

isTypestatic

Returns true if the passed instance is of the passed type.

ParameterTypeDescription
instanceObject

The object to test.

typeString

The type to test against

deepBoolean

Pass true to return true if the class is a subclass of the passed type.

Reconfigures an optional existing instance based on the provided config and returns the correctly configured instance. This will be the existingInstance if the config does not specify a different type.

If config is null (or simply falsy), this method will destroy the existingInstance (if any) and return null.

If there is no existingInstance, the config must specify a type. That is, it must be a string (the type name) or an object containing a type property, the defaultType must be provided or the factory itself must have a defaultType specified (see factoryable).

When an existingInstance is provided and a type is specified, the instance will be reconfigured via setConfig if it is of that type. Otherwise, the existingInstance is destroyed (if it is owned by the options.owner) and a new instance of the correct type is created.

ParameterTypeDescription
existingInstanceObject

The instance to reconfigure. This can be null.

configString | Object

The type name string or config object.

optionsString | function | Object

Additional options to control the reconfiguration process. If this value is a string or a class constructor, it treated as options.type. If this value is a class instance, it is used as the options.owner. If this is a function, it is treated as options.setup. NOTE: functions declared using the function keyword are equivalent to class constructors. Use an arrow function or a class method to avoid this when a setup function is intended.

options.typeString | function

The default type to use if the config object does not specify a type.

options.ownerObject

The owner of any created instances. If the existingInstance is being replaced, this value determines if the instance will be destroyed.

options.defaultsObject

A config object of default values to use when creating a new instance.

options.setupfunction | String

A function or the name of a method (on the options.owner) to call prior to creating a new instance. It is passed the config object that will be used to create the instance. If a truthy value is returned, that value is passed to the constructor instead of the provided config object.

options.transformfunction | String

A function or the name of a method (on the options.owner) to call with the raw config object prior to processing and the value it returns replaces the raw value. This function is used to transform strings or arrays (for example) into proper config objects.

options.cleanupfunction | String

A function or the name of a method (on the options.owner) to call prior to destroying the existingInstance. The existingInstance is passed as the sole argument.

Returns: Object -

The reconfigured instance (either existingInstance or a new instance of the desired type)

This method returns the constructor of the class registered for the given type name.

ParameterTypeDescription
typeString

The type name to look up.

optionalBoolean

Pass true to return null if type is not found instead of throwing an exception.

Returns: function