Baja Type Registry.
At the core of BajaScript is a lazily loading Type and Contract
system. A Contract represents a frozen slot definition for a Complex
or a set of FrozenEnum ordinals, tags and display tags.
The most commonly used Types are held in a Common Type Library that
is built into BajaScript to avoid unnecessary network calls.
Methods
-
<static> getAgents(ords [, is] [, batch])
-
Make a query for an agent list. This can be made against
a type (i.e. 'type:moduleName:TypeName') or a BObject resolved
from an ORD (i.e. 'station:|slot:/MyComponent').If an array of ORDs is passed in the response will resolve with an Object.
Every key in that object will be an ORD String. Each value in the Object will
contain an array of Agent Info. An Agent Info object contains a 'typeSpec',
'id', 'displayName' and 'icon' String property. If a single
ORD was passed in then the response will be an array of Agent Infos.Parameters:
Name Type Argument Description ords
String | baja.Ord | Array.<(String|baja.Ord)> An ORD or a number of ORDs
in an array to make an agent list query for.is
Array.<String> <optional>
An optional list of type specs to make a query against.
batch
baja.comm.Batch <optional>
If specified, the request is batched.
Returns:
A promise that will be resolved once completed.
- Type
- Promise
Examples
Get a Type's agent list.
baja.registry.getAgents("type:moduleName:TypeName") .then(function (agentInfos) { var i; for (i = 0; i < agentInfos.length; ++i) { console.log("typeSpec: " + agentInfos[i].typeSpec); console.log("id: " + agentInfos[i].id); console.log("displayName: " + agentInfos[i].displayName); console.log("icon: " + agentInfos[i].icon); } });
Get the Agent List from a mounted Component.
baja.registry.getAgents("station:|slot:/Folder/MyComponent") .then(function (agentInfos) { var i; for (i = 0; i < agentInfos.length; ++i) { console.log("typeSpec: " + agentInfos[i].typeSpec); console.log("id: " + agentInfos[i].id); console.log("displayName: " + agentInfos[i].displayName); console.log("icon: " + agentInfos[i].icon); } });
-
<static> getConcreteTypes(obj)
-
Get an array of concrete Types from the given typeInfo. This method
will make a network call. The type information returned in the
ok handler may not necessarily have Contract information loaded.
To then ensure the Contract information for Complex and FrozenEnums
is loaded, please use baja.importTypes.Parameters:
Name Type Description obj
Object the Object literal for the method's arguments.
Properties
Name Type Argument Description type
String | Type the type or (String type specification
- module:typeName) to query the registry for.
ok
function <optional>
(Deprecated: use Promise) the ok callback.
When invoked, an array of Types will be passed in as an argument.fail
function <optional>
(Deprecated: use Promise) the fail
callback.batch
baja.comm.Batch <optional>
If defined, the network call
will be batched into this object.- See:
Returns:
a promise that will be resolved
once the concrete Types have been retrieved.- Type
- Promise.<Array.<Type>>
Example
This method takes an object literal as an argument.
baja.registry.getConcreteTypes({ type: "control:ControlPoint", batch: batch // If specified, network calls are batched into this object }) .then(function (concreteTypes) { baja.outln('got concrete types: ' + concreteTypes.join()); }) .catch(function (err) { baja.error('failed to retrieve concrete types: ' + err); });
-
<static> hasType(typeSpec)
-
Does the Type exist in the BajaScript registry?
This method will not result in any network calls.
Parameters:
Name Type Description typeSpec
String the type specification to query the registry for.
Returns:
true if the Type exists in the BajaScript registry.
- Type
- Boolean
-
<static> importTypes()
-
Same as baja.importTypes.
- See:
-
<static> loadType()
-
Same as baja.lt.
- See: