new Component()
- Description:
Represents a
baja:Componentin BajaScript.Componentis the required base class for all
Baja component classes.Just like Niagara,
baja:Componentcontains a lot of the core
functionality of the framework. Unlikebaja:Struct, aComponentcan
contain both frozen and dynamicSlots. FrozenSlots are defined at
compile time (typically hard coded in Java) and DynamicSlots can be
added at runtime (i.e. when the Station is running). There are three
different types ofSlots that aComponentcan contain (Property,
ActionandTopic).
- Source:
- See:
Extends
Methods
add(obj) → {Promise.<baja.Property>}
- Description:
Add a dynamic
Propertyto a Component.If the value extends
baja:Action, the new slot is also an Action.
If the value extendsbaja:Topic, the new slot is also a Topic.If the
Complexis mounted, this will asynchronously add
thePropertyto theComponenton the server.For callbacks, the 'this' keyword is set to the Component instance.
- Source:
- See:
Example
An object literal is used to specify the method's arguments.
myObj.add({
slot: 'foo',
value: 'slot value',
facets: baja.Facets.make({ doo: 'boo'), // Optional
flags: baja.Flags.SUMMARY, // Optional
batch // if defined, any network calls will be batched into this object (optional)
})
.then(function (prop) {
baja.outln('added a new Property named "' + prop + '"');
})
.catch(function (err) {
baja.error('error adding Property: ' + err);
});
Parameters:
| Name | Type | Description | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
obj |
Object | the object literal for the method's arguments. Properties
|
Returns:
a promise that will be resolved with the
newly added Property.
- Type
- Promise.<baja.Property>
attach(event, func)
- Description:
Attach an Event Handler to this
Componentinstance.When an instance of
Componentis subscribed to aComponentrunning
in the Station, BajaScript can be used to listen for Component Events.An event handler consists of a name and a function. When the
function is called,thiswill map to the targetComponentthe handler
is attached to.For a list of all the event handlers and some of this method's more advanced
features, please see baja.Subscriber#attach.
- Source:
- See:
Example
A common event to attach to would be a Property changed event.
// myPoint is a mounted and subscribed Component...
myPoint.attach("changed", function (prop, cx) {
if (prop.getName() === "out") {
baja.outln("The output of the point is: " + this.getOutDisplay());
}
});
Parameters:
| Name | Type | Description |
|---|---|---|
event |
String | handler name |
func |
function | the event handler function |
canInvoke(ordTarget) → {boolean}
- Description:
If the target is to a slot within this component
then use the invoke permission based on the slot's
operator flag. If the target is the component itself
return if operator invoke is enabled.
- Source:
- Since:
- Niagara 4.12
Parameters:
| Name | Type | Description |
|---|---|---|
ordTarget |
module:baja/ord/OrdTarget |
Returns:
true if the component has required permissions to be invoked
- Type
- boolean
canRead(ordTarget) → {boolean}
- Description:
If the target is to a slot within this component
then use the read permission based on the slot's
operator flag. If the target is the component itself
return if operator read is enabled.
- Source:
- Since:
- Niagara 4.12
Parameters:
| Name | Type | Description |
|---|---|---|
ordTarget |
module:baja/ord/OrdTarget |
Returns:
true if the component has required permissions to be read
- Type
- boolean
canWrite(ordTarget) → {boolean}
- Description:
If the target is to a slot within this component
then use the write permission based on the slot's
readonly and operator flags. If the target is the
component itself return if operator write is enabled.
- Source:
- Since:
- Niagara 4.10
Parameters:
| Name | Type | Description |
|---|---|---|
ordTarget |
module:baja/ord/OrdTarget |
Returns:
true if the component has required permissions to be written into
- Type
- boolean
checkLink(obj) → {Promise.<baja.LinkCheck>}
- Description:
Check the validity of a link from the specified source
Componentto this
one.The target and source components must be mounted, leased / subscribed,
otherwise this function will fail.For callbacks, the
thiskeyword is set to theComponentinstance.
- Source:
Example
component.checkLink({
source: sourceComponent,
sourceSlot: 'sourceSlot',
targetSlot: 'myTargetSlot',
batch // if defined, any network calls will be batched into this object (optional)
})
.then(function (linkCheck) {
baja.outln('link checked: ' + linkCheck.isValid());
})
.catch(function (err) {
baja.error('failed to check link: ' + err);
});
Parameters:
| Name | Type | Description | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
obj |
baja.LinkCheck~LinkCreateInfo | the object literal for the Properties
|
Returns:
a promise that will be resolved with the
LinkCheck object.
- Type
- Promise.<baja.LinkCheck>
detach(hNameopt, funcopt)
- Description:
Detach an Event Handler from the
Component.If no arguments are used with this method then all events are removed.
For some of this method's more advanced features, please see
baja.Subscriber#detach.For a list of all the event handlers, please see baja.Subscriber#attach.
- Source:
- See:
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
hName |
String |
<optional> |
the name of the handler to detach from the Component. |
func |
function |
<optional> |
the function to remove from the Subscriber. It's recommended to supply this just in case |
doCheckLink(obj) → {null|LinkCheck|Promise.<LinkCheck>}
- Description:
This is an override point to specify additional link checking
between the specified source and the target slot. The default
implementation is to return undefined, delegating the link checking to the
station. If you know the link is valid without checking the station,
return or resolve LinkCheck.makeValid(). If you know the link would result
in an error condition then return or resolve to an invalid LinkCheck
with the appropriate reason.
- Source:
Parameters:
| Name | Type | Description | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
obj |
baja.LinkCheck~LinkCreateInfo | the object literal for the Properties
|
Returns:
a falsy value to delegate
the decision to the server. Otherwise, return a LinkCheck object, or a
promise resolving to one.
- Type
- null | LinkCheck | Promise.<LinkCheck>
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
fire(obj) → {Promise}
- Description:
Fire a Topic.
If the Component is mounted, this will asynchronously fire
the Topic on the Component in the Server.For callbacks, the
thiskeyword is set to the Component instance.
- Source:
Examples
A Slot, Slot name or an object literal can used for the method's arguments.
// Fire the Topic via its Topic Slot...
myObj.fire(fooTopic);
// ...or via the Topic's Slot name...
myObj.fire("foo");
// ...or for more arguments, use an object literal...
myObj.fire({
slot: topicSlot, // Can also be a Topic Slot name
value: "the Topic event argument",
batch // if defined, any network calls will be batched into this object (optional)
})
.then(function () {
baja.outln('topic has been fired');
})
.catch(function (err) {
baja.error('error firing topic: ' + err);
});
Please note that auto-generated convenience methods are created and added to a Component for firing frozen Topics. If the name of the auto-generated Topic method is already used, BajaScript will attach a number to the end of the method name so it becomes unique.
// Fire a Topic called 'foo'
myObj.fireFoo();
// Fire a Topic called foo with an event argument...
myObj.fireFoo("the Topic event argument");
// ...or via an object literal for more arguments...
myObj.fireFoo({
value: "the Topic event argument",
batch // if defined, any network calls will be batched into this object (optional)
})
.then(function () {
baja.outln('topic has been fired');
})
.catch(function (err) {
baja.error('error firing topic: ' + err);
});
Parameters:
| Name | Type | Description | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
obj |
baja.Action | String | Object | the Topic, Topic name or object Properties
|
Returns:
a promise that will be resolved once the Topic has been
fired.
- Type
- Promise
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
getActionParameterDefault(obj) → {Promise.<(baja.Value|null)>}
- Description:
Returns the default parameter for an Action.
For unmounted Components, by default it calls
baja.ActionProperty#getParamDefault. If mounted in a Proxy
Component Space, this will result in an asynchronous network call.For callbacks, the
thiskeyword is set to theComponentinstance.
- Source:
Example
// A resolved and mounted Component...
myComp.getActionParameterDefault({
slot: 'myAction',
batch // if defined, any network calls will be batched into this object (optional)
})
.then(function (param) {
if (param === null) {
baja.outln('action takes no parameters');
} else {
baja.outln('action parameter is: ' + param);
}
})
.catch(function (err) {
baja.error('could not retrieve action parameter: ' + err);
});
Parameters:
| Name | Type | Description | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
obj |
Object | the object literal for the method's arguments. Properties
|
Returns:
a promise that will be resolved once
the callbacks have been invoked.
- Type
- Promise.<(baja.Value|null)>
getAgents(isopt, batch) → {Promise.<Array.<Object>>}
- Description:
Returns a promise that resolves to the agent list for this component.
- Source:
- Overrides:
- See:
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
is |
Array.<String> |
<optional> |
An optional array of filters to add to the |
batch |
baja.comm.Batch | An optional object used to batch network |
Returns:
A promise that will resolve with the
Agent Info.
- Type
- Promise.<Array.<Object>>
getComponentSpace()
- Description:
Return the Component Space.
- Source:
Returns:
the Component Space for this Component (if mounted) otherwise return null.
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
getHandle() → {String|null}
- Description:
Return the
Component's handle.
- Source:
Returns:
handle for this Component (if mounted), otherwise
null.
- Type
- String | null
getHandlers(hName) → {Array.<function()>}
- Description:
Return an array of event handlers.
For a list of all the event handlers, please see
baja.Subscriber#attach.To access multiple handlers, insert a space between the handler names.
- Source:
- See:
Parameters:
| Name | Type | Description |
|---|---|---|
hName |
String | the name of the handler |
Returns:
- Type
- Array.<function()>
getIcon() → {baja.Icon}
- Description:
Return the Icon for the
Component
- Source:
- Overrides:
Returns:
- Type
- baja.Icon
getKnobCount() → {Number}
- Description:
Return the knob count for the
Component.
- Source:
Returns:
the number of knobs installed on the Component
- Type
- Number
getKnobs(slotopt) → {Array.<Object>}
- Description:
Return the Knobs for a particular Slot or the whole
Component.If no slot is passed in all the knobs for the
Componentwill be returned.
- Source:
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
slot |
baja.Slot | String |
<optional> |
the Slot or Slot name. |
Returns:
array of knobs
- Type
- Array.<Object>
getLinks(slotopt) → {Array.<baja.Struct>}
- Description:
Return the Links for a particular Slot or the whole
Component.If no slot is passed in all the links for the
Componentwill be returned.
- Source:
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
slot |
baja.Slot | String |
<optional> |
the |
Returns:
array of links.
- Type
- Array.<baja.Struct>
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
getNavChildren()
- Description:
Access the Nav Children for the
Component.
- Source:
- See:
getNavDescription() → {String}
- Description:
Return the Nav Description for the
Component.
- Source:
Returns:
- Type
- String
getNavDisplayName() → {String}
- Description:
Return the Nav Display Name for the
Component.
- Source:
Returns:
- Type
- String
getNavIcon() → {baja.Icon}
- Description:
Return the Nav Icon for the
Component
- Source:
Returns:
- Type
- baja.Icon
getNavName() → {String}
- Description:
Return the Nav Name for the
Component.
- Source:
Returns:
- Type
- String
getNavOrd(paramsopt) → {baja.Ord}
- Description:
Return the Nav ORD for the
Component.
- Source:
- See:
Parameters:
| Name | Type | Attributes | Description | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
params |
object |
<optional> |
Properties
|
Returns:
the Nav ORD or null if it's not mounted.
- Type
- baja.Ord
getNavParent()
- Description:
Return the Nav Parent for the
Component.
- Source:
Returns:
parent Nav Node
getNavTypeSpec() → {String}
- Description:
Return the type if the object the nav node navigates too.
For a Component, this is just a string version of its own type spec.
- Source:
Returns:
The nav node type spec.
- Type
- String
getOrdInSession() → {baja.Ord}
- Description:
Return the ORD in session for this
Component.
- Source:
Returns:
ORD in Session for this Component (or null if not mounted).
- Type
- baja.Ord
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
getPermissions() → {baja.Permissions}
- Description:
Return the permissions for this
Component.
- Source:
Returns:
- Type
- baja.Permissions
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
getRelationKnob(id) → {Object|null}
- Description:
Return the relation knob for the specified id.
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
id |
String | The id. |
Returns:
The relation knob or null if nothing can be found.
- Type
- Object | null
getRelationKnobCount() → {Number}
- Description:
Return the relation knob count for the component.
- Source:
Returns:
The number of relation knobs installed on the component.
- Type
- Number
getRelationKnobs() → {Array.<Object>}
- Description:
Return all of the relation knobs for the component.
- Source:
Returns:
An array of relation knobs.
- Type
- Array.<Object>
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
getSlotPath() → {baja.SlotPath}
- Description:
Return the Slot Path of the
Component.
- Source:
Returns:
the Slot Path or null if not mounted.
- Type
- baja.SlotPath
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
getUniqueName(slotName) → {String}
- Description:
Return a unique name for a potential new Slot in this
Component.Please note, this method inspects the current Slots this Component has loaded
to find a unique name. Therefore, if this Component is a Proxy, it must be
fully loaded and subscribed. Also please refrain from using this method in a
batch operation since it's likely the other operations in the batch will influence
a Slot name's uniqueness.
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
slotName |
String | the initial Slot name used to ensure uniqueness. This must be |
Returns:
a unique name.
- Type
- String
getValueOf(prop)
- Description:
Return the result of
valueOfon the specified Property's value.
IfvalueOfis not available then theProperty's value is returned.
- Source:
- Inherited From:
- 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
hasHandlers(hNameopt) → {Boolean}
- Description:
Return true if there any handlers registered for the given handler name.
If no handler name is specified then test to see if there are any
handlers registered at all.Multiple handlers can be tested for by using a space character between the names.
For a list of all the event handlers, please see
baja.Subscriber#attach.
- Source:
- See:
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
hName |
String |
<optional> |
the name of the handler. If undefined, then see if there are any |
Returns:
- Type
- Boolean
invoke(obj) → {Promise.<(baja.Value|null)>}
- Description:
Invoke an Action.
If the
Componentis mounted, this will asynchronously invoke
the Action on the Component in the Server.For callbacks, the
thiskeyword is set to theComponentinstance.
- Source:
Examples
A Slot, Slot name or an object literal can used for the method's arguments.
// Invoke the Action via its Action Slot...
myObj.invoke(fooAction);
// ...or via the Action's Slot name...
myObj.invoke("foo");
// ...or for more arguments, use an object literal...
myObj.invoke({
slot: actionSlot, // Can also be an Action Slot name
value: 'the Action argument',
batch // if defined, any network calls will be batched into this object (optional)
})
.then(function (returnValue) {
baja.outln('action successfully invoked and returned: ' + returnValue);
})
.catch(function (err) {
baja.error('error invoking action: ' + err);
});
Please note that auto-generated convenience methods are created and added to a Component for invoking frozen Actions. If the name of the auto-generated Action method is already used, BajaScript will attach a number to the end of the method name so it becomes unique. For example, the 'set' Action on a NumericWritable would be called 'set1' because Component already has a 'set' method.
// Invoke an Action called 'override'. Pass in an argument
myPoint.override(overrideVal);
// ...or via an object literal for more arguments...
myPoint.override({
value: overrideVal
batch // if defined, any network calls will be batched into this object (optional)
})
.then(function (returnValue) {
baja.outln('action successfully invoked and returned: ' + returnValue);
})
.catch(function (err) {
baja.error('error invoking action: ' + err);
});
Parameters:
| Name | Type | Description | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
obj |
baja.Action | String | Object | the Action, Action name or object Properties
|
Returns:
a promise that will be resolved once
the Action has been invoked.
- Type
- Promise.<(baja.Value|null)>
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
isMounted() → {Boolean}
- Description:
Return true if the
Componentis mounted inside a Space.
- Source:
Returns:
- Type
- Boolean
isNavChild() → {Boolean}
- Description:
Return true if this Component is a Nav Child.
- Source:
Returns:
true if this Component is a Nav Child.
- Type
- Boolean
isSubscribed() → {Boolean}
- Description:
Is the component subscribed?
- Source:
Returns:
- Type
- Boolean
lease(objopt) → {Promise}
- Description:
Subscribe a
Componentfor a period of time.The default lease time is 10 seconds.
Please note that a baja.Subscriber can also be used to put a
Componentinto and out of subscription.If the
Componentis mounted and it can be subscribed, this will result in
an asynchronous network call.If
leaseis called while theComponentis already leased, the timer
will just be renewed.For callbacks, the
thiskeyword is set to theComponentinstance.
- Source:
- See:
Example
A time (Number or baja.RelTime) or an object literal can be used to specify the method's arguments.
// Lease for 15 seconds
myComp.lease(15000);
// ...or lease for 2 and half minutes...
myComp.lease(baja.RelTime.make({minutes: 2, seconds: 30}));
// ...or lease using an object literal for more arguments...
myComp.lease({
time: 1000, // in milliseconds. Can also be a RelTime.
batch // if defined, any network calls will be batched into this object (optional)
})
.then(function () {
baja.outln('component has been leased');
})
.catch(function (err) {
baja.error('failed to lease component: ' + err);
});
Parameters:
| Name | Type | Attributes | Description | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
obj |
Number | baja.RelTime | Object |
<optional> |
the number of milliseconds, Properties
|
Returns:
a promise that will be resolved once the component has
been subscribed.
- Type
- Promise
loadSlots(objopt) → {Promise}
- Description:
Load all of the Slots on the
Component.If the
Componentis mounted and it can be loaded, this will result in
an asynchronous network call.For callbacks, the
thiskeyword is set to theComponentinstance.
- Source:
- Overrides:
Example
An optional object literal can be used to specify the method's arguments.
myComp.loadSlots({
batch // if defined, any network calls will be batched into this object (optional)
})
.then(function () {
baja.outln('slots have been loaded');
})
.catch(function (err) {
baja.error('failed to load slots: ' + err);
});
Parameters:
| Name | Type | Attributes | Description | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
obj |
object |
<optional> |
Properties
|
Returns:
a promise that will be resolved once the slots have
been loaded.
- Type
- Promise
makeLink(obj) → {Promise.<baja.Struct>}
- Description:
Create an instance of a Link to link from the specified source component
to this one.For unmounted
Components, by default this method resolves a plain
baja:Linkinstance. If mounted in a Proxy Component Space, this will
result in an asynchronous network call.For callbacks, the
thiskeyword is set to theComponentinstance.
- Source:
Example
component.makeLink({
source: sourceComponent,
sourceSlot: 'sourceSlot',
targetSlot: 'myTargetSlot',
batch // if defined, any network calls will be batched into this object (optional)
})
.then(function (link) {
baja.outln('link created: ' + link);
})
.catch(function (err) {
baja.error('failed to create link: ' + err);
});
Parameters:
| Name | Type | Description | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
obj |
baja.LinkCheck~LinkCreateInfo | the object literal for the Properties
|
Returns:
a promise that will be resolved with the
newly added Link.
- Type
- Promise.<baja.Struct>
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>
relations(objopt) → {Promise.<baja/tag/ComponentRelations>}
- Description:
Returns a promise that resolves to the Component's relations. If the
Component is mounted under a Proxy Component Space, a network call will be
made for the Component's implied relations to include into the result.
- Source:
Example
component.relations({
batch // if defined, any network calls will be batched into this object (optional)
})
.then(function (relations) {
baja.outln(relations.getAll().map(function (relation) {
return relation.getId() + ' = ' + relation.getEndpointOrd();
}).join());
})
.catch(function (err) {
baja.error('failed to retrieve relations: ' + err);
});
Parameters:
| Name | Type | Attributes | Description | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
obj |
Object |
<optional> |
the object literal for the method's arguments. Properties
|
Returns:
a promise that resolves
to the Component's relations.
- Type
- Promise.<baja/tag/ComponentRelations>
remove(obj) → {Promise}
- Description:
Remove the dynamic
Slotby the specified name.If the
Complexis mounted, this will asynchronously remove
the Property from theComponenton the server.For callbacks, the 'this' keyword is set to the Component instance.
- Source:
Example
The Slot, Slot name, a Complex or an object literal can be used for the method's arguments.
myObj.remove("foo");
//...or via the Slot itself...
myObj.remove(theFooSlot);
//...or remove the Complex instance from the parent...
myObj.remove(aComplexInstance);
//... of if more arguments are needed then via object literal notation...
myObj.remove({
slot: 'foo',
batch // if defined, any network calls will be batched into this object (optional)
})
.then(function () {
baja.outln('Property has been removed');
})
.catch(function (err) {
baja.error('error removing Property: ' + err);
});
Parameters:
| Name | Type | Description | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
obj |
baja.Slot | String | Object | the Slot, Slot name, Properties
|
Returns:
a promise that will be resolved once the Property has
been removed.
- Type
- Promise
rename(obj) → {Promise}
- Description:
Rename the specified dynamic Slot.
If the
Componentis mounted, this will asynchronously rename
the Slot in the Component on the server.For callbacks, the
thiskeyword is set to the Component instance.
- Source:
Example
An object literal is used for the method's arguments.
myObj.rename({
slot: 'foo',
newName: 'boo',
batch // if defined, any network calls will be batched into this object (optional)
})
.then(function () {
baja.outln('slot has been renamed');
})
.catch(function (err) {
baja.error('error renaming slot: ' + err);
});
Parameters:
| Name | Type | Description | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
obj |
Object | the object literal used for the method's arguments. Properties
|
Returns:
a promise that will be resolved once the slot has been
renamed.
- Type
- Promise
reorder(obj) → {Promise}
- Description:
Reorder the
Component's dynamic Properties.If the
Componentis mounted, this will asynchronously reorder
the dynamic Properties in the Component on the Server.For callbacks, the
thiskeyword is set to theComponentinstance.
- Source:
Example
A Property array or an object literal can used for the method's arguments.
// Order via an array of Properties...
myObj.reorder([booProp, fooProp, dooProp]);
// ...or order via an array of Property names...
myObj.reorder(["boo", "foo", "doo"]);
// ...or for more arguments, use an object literal...
myObj.reorder({
dynamicProperties: [booProp, fooProp, dooProp], // Can also be a Property name array!
batch // if defined, any network calls will be batched into this object (optional)
})
.then(function () {
baja.outln('slots have been reordered');
})
.catch(function (err) {
baja.outln('error reordering slots: ' + err);
});
Parameters:
| Name | Type | Description | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
obj |
Array.<(baja.Property|String)> | Object | the array of Properties Properties
|
Returns:
a promise that will be resolved once the dynamic
properties have been reordered.
- Type
- Promise
rpc(methodName) → {Promise.<(baja.Value|null)>}
- Description:
Invokes a Niagara RPC call on the Component running in the Station.
The method must implement the 'NiagaraRpc' annotation.Any extra arguments passed in will be encoded in raw JSON and passed up
to the Server. If one of those arguments is a 'baja.comm.Batch', the
call will be batched accordingly.
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
methodName |
String | The method name of the RPC call to invoke on |
Returns:
A promise that is resolved once the
RPC call has completed. If the Station RPC call returns a value then it
will be encoded and returned as a value in the promise.
- Type
- Promise.<(baja.Value|null)>
serverSideCall(obj) → {Promise.<(baja.Value|null)>}
- Description:
Make a Server Side Call.
Sometimes it's useful to invoke a method on the server from BajaScript.
A Server Side Call is how this is achieved.This will result in an asynchronous network call.
In order to make a Server Side Call, the developer needs to first create a
Niagara (Server Side) class that implements the
box:javax.baja.box.BIServerSideCallHandlerinterface.
The implementation should also declare itself as an Agent on the target
Component Type (more information in Java interface docs).
For callbacks, the 'this' keyword is set to the Component instance.
- Source:
Example
Here's an example of how a method implemented by this handler can be invoked.
// A resolved and mounted Component...
myComp.serverSideCall({
typeSpec: "foo:MyServerSideCallHandler", // The TypeSpec (moduleName:typeName) of the Server Side Call Handler
methodName: "bar", // The name of the public method we wish to invoke in the handler
value: "the argument for the method", // The argument to pass into the method (this can be any Baja Object/Component structure).
It will be deserialized automatically by Niagara.
batch // if defined, any network calls will be batched into this object (optional)
})
.then(function (returnValue) {
baja.outln('server side call has completed with: ' + returnValue);
})
.catch(function (err) {
baja.error('server side call failed: ' + err);
});
Parameters:
| Name | Type | Description | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
obj |
Object | the object literal for the method's arguments. Properties
|
Returns:
a promise that will be resolved once
the server side call has completed.
- Type
- Promise.<(baja.Value|null)>
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
setDisplayName(obj) → {Promise}
- Description:
Sets display names of one or more slots of this component.
If an empty string is given for obj.newDisplayName, the display name will
be removed.
In addition to firing "added" or "changed" component events on this
component, a synthetic "rename" event is also fired on each of the slot
whose display name is changed.
- Source:
- Since:
- Niagara 4.13
Parameters:
| Name | Type | Description | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
obj |
Object |
Properties
|
Returns:
- Type
- Promise
setFacets(obj) → {Promise}
- Description:
Set a dynamic Slot's facets.
If the
Complexis mounted, this will *asynchronously change the
facets on the server.For callbacks, the
thiskeyword is set to the Component instance.
- Source:
Example
An object literal is used to specify the method's arguments.
myObj.setFacets({
slot: 'outsideAirTemp',
facets: baja.Facets.make({ foo: 'boo' }),
batch // if defined, any network calls will be batched into this object (optional)
})
.then(function () {
baja.outln('facets have been set');
})
.catch(function (err) {
baja.error('error setting facets: ' + err);
});
Parameters:
| Name | Type | Description | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
obj |
Object | the object literal for the method's arguments. Properties
|
Returns:
a promise that will be resolved once the Facets have
been set.
- Type
- Promise
setFlags(obj) → {Promise}
- Description:
Set a Slot's flags.
If the
Complexis mounted, this will asynchronously set the Slot
Flags on the server.For callbacks, the
thiskeyword is set to theComponentinstance.
- Source:
Example
An object literal is used to specify the method's arguments.
myObj.setFlags({
slot: 'outsideAirTemp',
flags: baja.Flags.SUMMARY,
batch // if defined, any network calls will be batched into this object (optional)
})
.then(function () {
baja.outln('flags were set');
})
.catch(function (err) {
baja.error('error setting flags: ' + err);
});
Parameters:
| Name | Type | Description | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
obj |
Object | the object literal for the method's arguments. Properties
|
Returns:
a promise that will be resolved once the flags have been
set.
- Type
- Promise
tags(obj) → {Promise.<module:baja/tag/ComponentTags>}
- Description:
Returns a promise that resolves to the Component's tags. If the Component
is mounted under a Proxy Component Space, a network call will be made
for the Component's implied tags to include into the result.
- Source:
Example
component.tags({
batch // if defined, any network calls will be batched into this object (optional)
})
.then(function (tags) {
baja.outln(tags.getAll().map(function (tag) {
return tag.getId() + ' = ' + tag.getValue();
}).join());
})
.catch(function (err) {
baja.error('failed to retrieve tags: ' + err);
});
Parameters:
| Name | Type | Description | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
obj |
Object | the object literal for the method's arguments. Properties
|
Returns:
a promise that resolves
to the Component's tags.
- Type
- Promise.<module:baja/tag/ComponentTags>
toPathString() → {String}
- Description:
Return the path string of the
Component.
- Source:
Returns:
the Path String or null if not mounted.
- Type
- String
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
- *
(static) lease(obj) → {Promise}
- Description:
Subscribe a number of
Components for a period of time.The default period of time is 10 seconds.
Please note that a baja.Subscriber can also be used to put a
Componentinto and out of subscription.If the
Componentis mounted and it can be subscribed, this will result in
an asynchronous network call.If any of the the
Components are already leased, the lease timer will
just be renewed.For callbacks, the
thiskeyword is set to whatever thecompsargument
was originally set to.
- Source:
- See:
Example
A time (Number or baja.RelTime) or an object literal can be used to specify the method's arguments.
// Lease an array of Components for the default time period
myComp.lease([comp1, comp2, comp3]);
// ...or lease for 2 and half minutes...
myComp.lease({
time: baja.RelTime.make({minutes: 2, seconds: 30}),
comps: [comp1, comp2, comp3]
})
.then(function () {
baja.outln('components have been subscribed');
})
.catch(function (err) {
baja.outln('components failed to subscribe: ' + err);
});
Parameters:
| Name | Type | Description | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
obj |
Object | an object literal for the method's arguments. Properties
|
Returns:
a promise that will be resolved once the component(s)
have been subscribed.
- Type
- Promise