new Struct()
- Description:
Represents a
baja:Structin BajaScript.Structis the base class for a component which has
one or more properties.Structs must only declare
properties which are typed as boolean, int, float,
String, Simple, or otherStructs. This means
that aStructmay never have aComponentproperty.
Structs only supportPropertyslots, neverActions orTopics.A
Structcan only contain frozen Slots. A frozen Slot is defined
at compile time (usually hard coded in Java).
- Source:
- See:
Extends
Methods
equals(obj) → {Boolean}
- Description:
Indicates whether some other object is equal to this one.
- Source:
- Inherited From:
Parameters:
| Name | Type | Description |
|---|---|---|
obj |
Object | the reference object with which to compare. |
Returns:
true if this object is the same as the obj argument; false otherwise.
- Type
- Boolean
equivalent(obj) → {Boolean}
- Description:
Compare if all of this object's properties are equal to the specified object.
- Source:
- Inherited From:
Parameters:
| Name | Type | Description |
|---|---|---|
obj |
baja.Complex |
Returns:
true if this object is equivalent to the specified object.
- Type
- Boolean
get(prop) → {baja.Value}
- Description:
Return a
Property's value.Note that when an instance of a
Complexis created, auto-generated
accessors are created to make accessing a frozenProperty's value
convenient (see example).Performance notes:
BajaScript performs "lazy decoding" on Complexes - this means that after a
Complex is retrieved from the station, its slot values are kept in their
raw JSON encoding until they are actually needed (by callingget()). This
helps performance by not spending CPU time decoding values that won't be
used. It follows that callinggetSlot(slot)will be much faster than
callingget(slot)for the first time, so consider filtering on slots
rather than on values, if possible, in performance-critical situations. See
example undergetSlots().
- Source:
- Inherited From:
- See:
Example
Note that when an instance of a Complex is created,
auto-generated setters are created to make setting a frozen Property's
value convenient. The auto-generated setter is in the format of
set(first letter is capitalized)SlotName(...).
// myPoint has a frozen Property named out...
var val = myPoint.getOut();
val = myPoint.get('out'); //equivalent
Parameters:
| Name | Type | Description |
|---|---|---|
prop |
baja.Property | String | the Property or Property name. |
Returns:
the value for the Property (null if the Property doesn't exist).
- Type
- baja.Value
getAgents(isopt, batchopt) → {Promise}
- Description:
Returns a promise that resolves to the agent list for this Object.
- Source:
- Inherited From:
- See:
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
is |
Array.<String> |
<optional> |
An optional array of filters to add to the |
batch |
baja.comm.Batch |
<optional> |
An optional object used to batch network |
Returns:
A promise that will resolve with the Agent Info.
- Type
- Promise
getDisplay(slotopt, cxopt) → {String|null|Promise.<(String|null)>}
- Description:
Return a display string.
If a Slot argument is defined, the display value for the Slot will be
returned. If a Slot argument is not defined, the display value for the
Complex will be returned.
- Source:
- Inherited From:
Example
Printing display values of slots
// myPoint has a Property named out...
baja.outln('The display string of the out Property: ' + myPoint.getDisplay('out'));
// or use string formatting:
return myPoint.getDisplay('out', { precision: 5 })
.then(function (str) { baja.outln('formatted display string: ' + str); });
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
slot |
baja.Property | String |
<optional> |
the Slot or Slot name. |
cx |
object |
<optional> |
as of Niagara 4.10, you can pass a context as the |
Returns:
display (or null if none available).
getDisplayName(slotopt) → {String}
- Description:
Return a display name.
If a Slot is defined as an argument, the display name for the slot will
be returned. If no Slot is defined, the display name of theComplex
will be returned.
- Source:
- Inherited From:
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
slot |
baja.Slot | String |
<optional> |
the Slot or Slot name. |
Returns:
the display name (or null if none available).
- Type
- String
getFacets(slotopt) → {baja.Facets}
- Description:
Return the
Facetsfor a Slot.If no arguments are provided and the
Complexhas a parent, the
facets for the parent's Property will be returned.
- Source:
- Inherited From:
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
slot |
baja.Slot | String |
<optional> |
the |
Returns:
the Facets for the Slot (or null if Slot not
found) or the parent's Property facets.
- Type
- baja.Facets
getFlags(slotopt) → {Number}
- Description:
Return
Flagsfor a slot or for theComplex's parent Property.If no arguments are provided and the
Complexhas a parent, the
flags for the parent'sPropertywill be returned.
- Source:
- Inherited From:
- See:
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
slot |
baja.Slot | String |
<optional> |
|
Returns:
the flags for the Slot or the parent's Property flags.
- Type
- Number
getIcon() → {baja.Icon}
- Description:
Return the Object's Icon.
- Source:
- Inherited From:
Returns:
- Type
- baja.Icon
getName() → {String}
- Description:
Return the name of the
Component.The name is taken from the parent
Component's Property for this
Componentinstance.
- Source:
- Inherited From:
Returns:
name (null if not mounted).
- Type
- String
getParent() → {baja.Complex}
- Description:
Return the parent.
- Source:
- Inherited From:
Returns:
parent
- Type
- baja.Complex
getParentComponent() → {baja.Component|null}
- Description:
Get the nearest ancestor of this object which is
an instance ofComponent. If this object is itself
aComponent, then returnthis. Return
null if this object doesn't exist under aComponent.
- Source:
- Since:
- Niagara 4.10
- Inherited From:
Returns:
- Type
- baja.Component | null
getPropertyInParent() → {baja.Property}
- Description:
Return the
Propertyin the parent.
- Source:
- Inherited From:
Returns:
the Property in the parent (null if not mounted).
- Type
- baja.Property
getSlot(slot) → {baja.Slot}
- Description:
Return the
Slot.This is useful method to ensure you have the
Slotinstance instead of the
Slot name String. If aSlotis passed in, it will simply be checked and
returned.
- Source:
- Inherited From:
Parameters:
| Name | Type | Description |
|---|---|---|
slot |
baja.Slot | String | the |
Returns:
the Slot for the Component (or null if the
Slot doesn't exist).
- Type
- baja.Slot
getSlots(filteropt) → {module:baja/comp/SlotCursor}
- Description:
Return a
Cursorfor accessing aComplex's Slots.Please see module:baja/comp/SlotCursor for useful builder methods.
- Source:
- Inherited From:
- See:
Examples
// A Cursor for Dynamic Properties
var frozenPropCursor = myComp.getSlots().dynamic().properties();
// A Cursor for Frozen Actions
var frozenPropCursor = myComp.getSlots().frozen().actions();
// An Array of Control Points
var valArray = myComp.getSlots().properties().is("control:ControlPoint").toValueArray();
// An Array of Action Slots
var actionArray = myComp.getSlots().actions().toArray();
// An Object Map of slot name/value pairs
var map = myComp.getSlots().properties().toMap();
// The very first dynamic Property
var firstProp = myComp.getSlots().dynamic().properties().first();
// The very last dynamic Property
var lastProp = myComp.getSlots().dynamic().properties().last();
// The very first dynamic Property value
var firstVal = myComp.getSlots().dynamic().properties().firstValue();
// The very first dynamic Property value
var lastVal = myComp.getSlots().dynamic().properties().lastValue();
// All the Slots that start with the name 'foo'
var slotNameCursor = myComp.getSlots().slotName(/^foo/);
// Use a custom Cursor to find all of the Slots that have a particular facets key/value
var custom = myComp.getSlots(function (slot) {
return slot.isProperty() && (this.getFacets(slot).get("myKey", "def") === "foo");
});
// Same as above
var custom2 = myComp.getSlots().filter(function (slot) {
return slot.isProperty() && (this.getFacets(slot).get("myKey", "def") === "foo");
});
// All Slots marked summary on the Component
var summarySlotCursor = myComp.getSlots().flags(baja.Flags.SUMMARY);
// Call function for each Property that's a ControlPoint
myComp.getSlots().is("control:ControlPoint").each(function (slot) {
baja.outln("The Nav ORD for the ControlPoint: " + this.get(slot).getNavOrd();
});
<caption>You may see better performance if you can filter on slots
instead of on values.<caption>
// slower
var links = component.getSlots().toValueArray()
.filter(function (value) { return value.getType().is('baja:Link'); });
// faster - this avoids unnecessarily decoding every non-Link slot
var links = component.getSlots().is('baja:Link').toValueArray();
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
filter |
function |
<optional> |
function to filter out the Slots we're not interested in. |
Returns:
a Cursor for iterating through the
Complex's Slots.
getType() → {Type}
- Description:
Get the type of this instance.
- Source:
- Inherited From:
Returns:
- Type
- Type
getTypeDisplayName(cxopt) → {Promise.<string>|string}
- Description:
Gets the friendly type display name for this object.
- Source:
- Since:
- Niagara 4.10
- Inherited From:
- See:
-
- baja.Type#getDisplayName
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
cx |
Object |
<optional> |
a context to be passed down to Type |
Returns:
If no context is provided, the type
display name is returned synchronously as a string. If context provided,
the type display name is resolved via a promise as a string.
- Type
- Promise.<string> | string
getValueOf(prop)
- Description:
Deprecated.
Return the result ofvalueOfon the specified Property's value.
IfvalueOfis not available then theProperty's value is returned.
- Source:
- Inherited From:
- Deprecated:
- see UI Changelog in Doc Developer
- See:
Parameters:
| Name | Type | Description |
|---|---|---|
prop |
baja.Property | String | the |
Returns:
the valueOf for the Property's value or the Property's
value (null if the Property doesn't exist).
has(prop) → {Boolean}
- Description:
Return true if the
Slotexists.
- Source:
- Inherited From:
Parameters:
| Name | Type | Description |
|---|---|---|
prop |
baja.Property | String | the Property or Property name |
Returns:
- Type
- Boolean
isAncestorOf(comp) → {boolean}
- Source:
- Since:
- Niagara 4.12
- Inherited From:
Parameters:
| Name | Type | Description |
|---|---|---|
comp |
baja.Complex | * | the descendent complex to test |
Returns:
if this Complex is an ancestor of the given Complex (but not the same
instance). Returns false if the given parameter is not actually a Complex.
- Type
- boolean
loadSlots(objopt) → {Promise}
- Description:
Load all of the Slots on the
Complex.
- Source:
- Inherited From:
- See:
Parameters:
| Name | Type | Attributes | Description | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
obj |
Object |
<optional> |
the object literal for the method's arguments. Properties
|
Returns:
a promise to be resolved when the slots have been
loaded.
- Type
- Promise
newCopy(exactopt) → {baja.Complex}
- Description:
Create a clone of this
Complex.If the
exactargument is true and thisComplexis aComponentthen
thedefaultOnCloneandremoveOnCloneflags will be ignored.
- Source:
- Inherited From:
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
exact |
Boolean |
<optional> |
false
|
flag to indicate whether to create an exact copy |
Returns:
cloned Complex.
- Type
- baja.Complex
propertyValueToString(slot, cxopt) → {Promise.<String>}
- Description:
Utilize the slot facets, context, and slot to resolve the proper toString.
- Source:
- Since:
- Niagara 4.11
- Inherited From:
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
slot |
baja.Property | String | ||
cx |
object |
<optional> |
the context |
Throws:
-
if the slot name isn't a Property.
- Type
- Error
Returns:
- Type
- Promise.<String>
set(obj) → {Promise}
- Description:
Set a
Property's value.If the Complex is mounted, this will asynchronously set the Property's
value on the Server.
- Source:
- Inherited From:
Examples
An object literal is used to specify the method's arguments.
myObj.set({
slot: "outsideAirTemp",
value: 23.5,
batch: myBatch // if defined, any network calls will be batched into this object (optional)
})
.then(function () {
baja.outln('value has been set on the server');
})
.catch(function (err) {
baja.error('value failed to set on the server: ' + err);
});
Note that when an instance of a Complex is created,
auto-generated setters are created to make setting a frozen Property's
value convenient. The auto-generated setter is in the format of
set(first letter is capitalized)SlotName(...).
// myPoint has a Property named outsideAirTemp...
myObj.setOutsideAirTemp(23.5);
// ... or via an Object Literal if more arguments are needed...
myObj.setOutsideAirTemp({ value: 23.5, batch: myBatch })
.then(function () {
baja.outln('value has been set on the server');
});
Parameters:
| Name | Type | Description | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
obj |
Object | the object literal for the method's arguments. Properties
|
Returns:
a promise that will be resolved once the value has been
set on the Complex. If the complex is mounted, will be resolved once the
value has been saved to the server.
- Type
- Promise
toString() → {String}
- Description:
Return the
Stringrepresentation.
- Source:
- Inherited From:
Returns:
- Type
- String
valueOf() → {*}
- Description:
Return the inner value of the object.
By default the object's instance is returned.
- Source:
- Inherited From:
Returns:
the inner value of the object or just the object's instance.
- Type
- *