Module: nmodule/webEditors/rc/wb/mgr/MgrTypeInfo


new (require("nmodule/webEditors/rc/wb/mgr/MgrTypeInfo"))()

API Status: Development

MgrTypeInfo wraps information about what type to create
in the station database when doing a new or add operation.
This information may come from an exact type, a registry
query for concrete types given a base type, or from a component
instance used as a prototype.

In addition to the basic type operations, this provides extra
functionality specific to the manager views, such as the ability
to compare and match types.

This constructor should be not called directly. Client code should
use the static .make() function.

Methods


<static> BY_DISPLAY_NAME()

Helper function to be passed to an array sorting function to ensure MgrTypeInfo instances are
ordered according to the display name.

Example

Sort the array of MgrTypeInfos obtained from the make() function.

MgrTypeInfo.make({
  from: 'baja:ControlPoint',
  concreteTypes: true
})
.then(function (mgrInfos) {
  mgrInfos.sort(MgrTypeInfo.BY_DISPLAY_NAME);
});

<static> make(params)

Static .make() function, returning a Promise that will resolve
to a single MgrTypeInfo or array of MgrTypeInfos, depending on the
arguments passed to the function. This is the normal way to obtain a
MgrTypeInfo instance; the type's constructor should not be used by client
code directly.

Parameters:
Name Type Description
params Object

an Object containing the function's arguments

Properties
Name Type Argument Description
from String | baja.Type | Array <optional>

The type spec used to create the
type information. This may be a single type spec string, or a BajaScript Type instance,
or may be an array of spec strings or Types.

concreteTypes Boolean <optional>

true if the from parameter should be used
as a base type to create an Array of MgrTypeInfos for its concrete types. If this parameter
is specified as true, the from parameter must contain a single base type.

batch baja.comm.Batch <optional>

An optional batch object, which if provided can be
used to batch network calls.

Returns:

Either a single MgrTypeInfo instance, or an array of MgrTypeInfos,
depending on the value passed in the 'from' parameter and the value of the 'concreteTypes'
parameter. If the 'from' parameter specifies a single type and 'concreteTypes' is either
false or undefined, the returned value will be a single MgrTypeInfo, otherwise the returned
value will be an array of MgrTypeInfos.

Type
Promise
Examples

Make an array of MgrTypeInfos from an array of type spec strings.

MgrTypeInfo.make({
  from: [ 'baja:AbsTime', 'baja:Date', 'baja.RelTime' ]
})
.then(function (mgrInfos) {
  // ... do something with the array of MgrTypeInfo
});

Get the concrete MgrTypeInfos for the abstract ControlPoint type.

MgrTypeInfo.make({
  from: 'baja:ControlPoint',
  concreteTypes: true
})
.then(function (mgrInfos) {
  // ... do something with the array of MgrTypeInfo
});

Get the MgrTypeInfos for the agents on a type

baja.registry.getAgents("type:moduleName:TypeName")
   .then(function (agentInfos) {
     return MgrTypeInfo.make({
       from: agentInfos
     });
   })
   .then(function (mgrInfos) {
     // ... do something with the array of MgrTypeInfo
   });

<static> markDuplicates(infos)

Static function to compare an array of MgrTypeInfos for duplicate type names.
This is used to alter the display name for any non-prototype created MgrTypeInfos,
where there may be two or more modules exposing types with the same display names.

Parameters:
Name Type Description
infos Array.<module:nmodule/webEditors/rc/wb/mgr/MgrTypeInfo>

equals(other)

Equality comparison for two MgrTypeInfo instances based on a comparison
of the display name. This will return false if the other object is not a
MgrTypeInfo instance.

Parameters:
Name Type Description
other Object

the object to be compared against

Returns:
Type
Boolean

getDisplayName()

Get the display name of the type to create.

Returns:
Type
String

getIcon()

Get the icon of the type to create.

Returns:
Type
baja.Icon

getType()

Get the BajaScript Type to be created by this MgrTypeInfo instance.

Returns:
Type
baja.Type

isMatchable(db)

Return true if this type may be used to perform a learn match against the
specified database component.

Parameters:
Name Type Description
db baja.Component

the database component

Returns:
Type
Boolean

newInstance()

Returns a Promise that will create a new instance of a component
from the type information.

Returns:
Type
Promise.<baja.Component>

toSlotName()

Get the type as a slot name. The default implementation
returns the display name stripped of spaces and escaped.

Returns:
Type
String

toString()

Returns the display name for the type represented by this instance.

Returns:
Type
String