Defines a BajaScript implementation of control:ControlPoint (not exposed
on baja namespace).
Methods
-
add(obj)
-
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.
Parameters:
Name Type Description objObject the object literal for the method's arguments.
Properties
Name Type Argument Description slotString the Slot name the unique name to use as the String
key for the slot. If null is passed, then a unique name will automatically
be generated. If the name ends with the '?' character a unique name will
automatically be generated by appending numbers to the specified name. The
name must meet the "name" production in the SlotPath BNF grammar.
Informally this means that the name must start with an ASCII letter and
contain only ASCII letters, ASCII digits, or '_'. Escape sequences can be
specified using the '$' char. Usebaja.SlotPath.escape()to escape
illegal characters.valuebaja.Value the value to be added
flagsNumber <optional>
optional Slot flags.
facetsbaja.Facets <optional>
optional Slot Facets.
okfunction <optional>
(Deprecated: use Promise) the ok callback. This
function is called once the Property has been added to the Server. The
function is passed the newPropertythat has just been added.failfunction <optional>
(Deprecated: use Promise) the fail callback.
This function is called if the Property fails to add. Any error information
is passed into this function.batchbaja.comm.Batch <optional>
if defined, any network calls will be
batched into this object.cx<optional>
the Context (used internally by BajaScript).
- Inherited From:
- See:
Returns:
a promise that will be resolved with the
newly added Property.- Type
- Promise.<baja.Property>
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); }); -
attach(event, func)
-
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.Parameters:
Name Type Description eventString handler name
funcfunction the event handler function
- Inherited From:
- 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()); } }); -
canWrite(ordTarget)
-
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.Parameters:
Name Type Description ordTargetmodule:baja/ord/OrdTarget - Since:
-
- Niagara 4.10
- Inherited From:
Returns:
true if the component has required permissions to be written into
- Type
- boolean
-
checkLink(obj)
-
Check the validity of a link to the specified source
Component.The target and source components must be mounted, leased / subscribed,
otherwise this function will fail.For callbacks, the
thiskeyword is set to theComponentinstance.Parameters:
Name Type Description objObject the object literal for the method's arguments.
Properties
Name Type Argument Description sourcebaja.Component the source Component for the link.
sourceSlotbaja.Slot | String the source Slot or Slot name.
targetSlotbaja.Slot | String the target Slot or Slot name.
okfunction <optional>
(Deprecated: use Promise) the ok callback. A
Link will be passed as an argument to this function.failfunction <optional>
(Deprecated: use Promise) the fail callback.
batchbaja.comm.Batch <optional>
if defined, any network calls will be
batched into this object.- Inherited From:
Returns:
a promise that will be resolved with the
LinkCheck object.- Type
- Promise.<baja.Struct>
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); }); -
detach( [hName] [, func])
-
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.
Parameters:
Name Type Argument Description hNameString <optional>
the name of the handler to detach from the Component.
funcfunction <optional>
the function to remove from the Subscriber. It's recommended to supply this just in case
other scripts have added event handlers. -
doCheckLink(obj)
-
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.Parameters:
Name Type Description objObject the object literal for the method's arguments.
Properties
Name Type Argument Description sourcebaja.Component the source Component for the LinkCheck.
sourceSlotbaja.Slot | String the source Slot or Slot name.
targetSlotbaja.Slot | String the target Slot or Slot name.
okfunction <optional>
(Deprecated: use Promise) the ok callback. A
LinkCheck will be passed as an argument to this function.failfunction <optional>
(Deprecated: use Promise) the fail callback.
batchbaja.comm.Batch <optional>
if defined, any network calls will be
batched into this object.- Inherited From:
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)
-
Indicates whether some other object is equal to this one.
Parameters:
Name Type Description objObject the reference object with which to compare.
- Inherited From:
Returns:
true if this object is the same as the obj argument; false otherwise.
- Type
- Boolean
-
equivalent(obj)
-
Compare if all of this object's properties are equal to the specified object.
Parameters:
Name Type Description objbaja.Complex - Inherited From:
Returns:
true if this object is equivalent to the specified object.
- Type
- Boolean
-
fire(obj)
-
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.Parameters:
Name Type Description objbaja.Action | String | Object the Topic, Topic name or object
literal for the method's arguments.Properties
Name Type Argument Description slotbaja.Action | String the Topic or Topic name.
value<optional>
the Topic's event.
okfunction <optional>
(Deprecated: use Promise) the ok callback. This
function is called once the Topic has been fired.failfunction <optional>
(Deprecated: use Promise) the fail callback.
This function is called if the Topic fails to fire. Any error information
is passed into this function.batchbaja.comm.Batch <optional>
if defined, any network calls will be
batched into this object.cx<optional>
the Context (used internally by BajaScript).
- Inherited From:
Returns:
a promise that will be resolved once the Topic has been
fired.- Type
- Promise
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); }); -
get(prop)
-
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).Parameters:
Name Type Description propbaja.Property | String the Property or Property name.
- Inherited From:
Returns:
the value for the Property (null if the Property doesn't exist).
- Type
- baja.Value
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 -
getActionParameterDefault(obj)
-
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.Parameters:
Name Type Description objObject the object literal for the method's arguments.
Properties
Name Type Argument Description slotbaja.Action | String the Action or Action name.
okfunction <optional>
(Deprecated: use Promise) the ok callback.
Called once the Action Parameter Default has been received. Any return
value is passed to this function (could be null if no Action parameter is
defined).failfunction <optional>
(Deprecated: use Promise) the fail callback.
batchbaja.comm.Batch <optional>
if defined, any network calls will be
batched into this object.- Inherited From:
Returns:
a promise that will be resolved once
the callbacks have been invoked.- Type
- Promise.<(baja.Value|null)>
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); }); -
getAgents( [is], batch)
-
Returns a promise that resolves to the agent list for this component.
Parameters:
Name Type Argument Description isArray.<String> <optional>
An optional array of filters to add to the
agent query.batchbaja.comm.Batch An optional object used to batch network
calls together.- Inherited From:
- See:
Returns:
A promise that will resolve with the
Agent Info.- Type
- Promise.<Array.<Object>>
-
getComponentSpace()
-
Return the Component Space.
- Inherited From:
Returns:
the Component Space for this
Component(if mounted) otherwise return null. -
getDisplay( [slot] [, cx])
-
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.Parameters:
Name Type Argument Description slotbaja.Property | String <optional>
the Slot or Slot name.
cxobject <optional>
as of Niagara 4.10, you can pass a context as the
second argument to use for string formatting. When a context is passed,
a Promise will be returned to be resolved with the formatted string.- Inherited From:
Returns:
display (or null if none available).
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); }); -
getDisplayName( [slot])
-
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.Parameters:
Name Type Argument Description slotbaja.Slot | String <optional>
the Slot or Slot name.
- Inherited From:
Returns:
the display name (or null if none available).
- Type
- String
-
getFacets( [slot])
-
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.Parameters:
Name Type Argument Description slotbaja.Slot | String <optional>
the
Slotor Slot name.- Inherited From:
Returns:
the
Facetsfor theSlot(or null if Slot not
found) or the parent's Property facets.- Type
- baja.Facets
-
getFlags( [slot])
-
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.Parameters:
Name Type Argument Description slotbaja.Slot | String <optional>
Slotor Slot name.- Inherited From:
- See:
Returns:
the flags for the
Slotor the parent'sPropertyflags.- Type
- Number
-
getHandle()
-
Return the
Component's handle.- Inherited From:
Returns:
handle for this Component (if mounted), otherwise
null.- Type
- String | null
-
getHandlers(hName)
-
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.
Parameters:
Name Type Description hNameString the name of the handler
- Inherited From:
- See:
Returns:
- Type
- Array.<function()>
-
getIcon()
-
Return the Icon for the
Component- Inherited From:
Returns:
- Type
- baja.Icon
-
getKnobCount()
-
Return the knob count for the
Component.- Inherited From:
Returns:
the number of knobs installed on the
Component- Type
- Number
-
getKnobs( [slot])
-
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.Parameters:
Name Type Argument Description slotbaja.Slot | String <optional>
the Slot or Slot name.
- Inherited From:
Returns:
array of knobs
- Type
- Array.<Object>
-
getLinks( [slot])
-
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.Parameters:
Name Type Argument Description slotbaja.Slot | String <optional>
the
Slotor Slot name.- Inherited From:
Returns:
array of links.
- Type
- Array.<baja.Struct>
-
getName()
-
Return the name of the
Component.The name is taken from the parent
Component's Property for this
Componentinstance.- Inherited From:
Returns:
name (null if not mounted).
- Type
- String
-
getNavChildren()
-
Access the Nav Children for the
Component.- Inherited From:
- See:
-
getNavDescription()
-
Return the Nav Description for the
Component.- Inherited From:
Returns:
- Type
- String
-
getNavDisplayName()
-
Return the Nav Display Name for the
Component.- Inherited From:
Returns:
- Type
- String
-
getNavIcon()
-
Return the Nav Icon for the
Component- Inherited From:
Returns:
- Type
- baja.Icon
-
getNavName()
-
Return the Nav Name for the
Component.- Inherited From:
Returns:
- Type
- String
-
getNavOrd( [params])
-
Return the Nav ORD for the
Component.Parameters:
Name Type Argument Description paramsobject <optional>
Properties
Name Type Argument Description sessionAwareboolean <optional>
- Inherited From:
- See:
Returns:
the Nav ORD or null if it's not mounted.
- Type
- baja.Ord
-
getNavParent()
-
Return the Nav Parent for the
Component.- Inherited From:
Returns:
parent Nav Node
-
getNavTypeSpec()
-
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.
- Inherited From:
Returns:
The nav node type spec.
- Type
- String
-
getOrdInSession()
-
Return the ORD in session for this
Component.- Inherited From:
Returns:
ORD in Session for this
Component(or null if not mounted).- Type
- baja.Ord
-
getParent()
-
Return the parent.
- Inherited From:
Returns:
parent
- Type
- baja.Complex
-
getParentComponent()
-
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.- Since:
-
- Niagara 4.10
- Inherited From:
Returns:
- Type
- baja.Component | null
-
getPermissions()
-
Return the permissions for this
Component.- Inherited From:
Returns:
- Type
- baja.Permissions
-
getPropertyInParent()
-
Return the
Propertyin the parent.- Inherited From:
Returns:
the
Propertyin the parent (null if not mounted).- Type
- baja.Property
-
getRelationKnob(id)
-
Return the relation knob for the specified id.
Parameters:
Name Type Description idString The id.
- Inherited From:
Returns:
The relation knob or null if nothing can be found.
- Type
- Object | null
-
getRelationKnobCount()
-
Return the relation knob count for the component.
- Inherited From:
Returns:
The number of relation knobs installed on the component.
- Type
- Number
-
getRelationKnobs()
-
Return all of the relation knobs for the component.
- Inherited From:
Returns:
An array of relation knobs.
- Type
- Array.<Object>
-
getSlot(slot)
-
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.Parameters:
Name Type Description slotbaja.Slot | String the
Slotor Slot name.- Inherited From:
Returns:
the
Slotfor theComponent(or null if the
Slotdoesn't exist).- Type
- baja.Slot
-
getSlotPath()
-
Return the Slot Path of the
Component.- Inherited From:
Returns:
the Slot Path or null if not mounted.
- Type
- baja.SlotPath
-
getSlots( [filter])
-
Return a
Cursorfor accessing aComplex's Slots.Please see module:baja/comp/SlotCursor for useful builder methods.
Parameters:
Name Type Argument Description filterfunction <optional>
function to filter out the Slots we're not interested in.
The filter function will be passed eachSlotto see if it should be
be included. The function must return false to filter out a value and true
to keep it.- Inherited From:
Returns:
a
Cursorfor iterating through theComplex's Slots.Example
// 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(); }); -
getType()
-
Get the type of this instance.
- Inherited From:
Returns:
- Type
- Type
-
getTypeDisplayName( [cx])
-
Gets the friendly type display name for this object.
Parameters:
Name Type Argument Description cxObject <optional>
a context to be passed down to Type
- Since:
-
- Niagara 4.10
- Inherited From:
- See:
-
- baja.Type#getDisplayName
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)
-
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.Parameters:
Name Type Description slotNameString the initial Slot name used to ensure uniqueness. This must be
a valid Slot name.- Inherited From:
Returns:
a unique name.
- Type
- String
-
getValueOf(prop)
-
Return the result of
valueOfon the specified Property's value.
IfvalueOfis not available then theProperty's value is returned.Parameters:
Name Type Description propbaja.Property | String the
Propertyor Property name.- Inherited From:
- See:
Returns:
the
valueOffor theProperty's value or theProperty's
value (null if thePropertydoesn't exist). -
has(prop)
-
Return true if the
Slotexists.Parameters:
Name Type Description propbaja.Property | String the Property or Property name
- Inherited From:
Returns:
- Type
- Boolean
-
hasHandlers( [hName])
-
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.Parameters:
Name Type Argument Description hNameString <optional>
the name of the handler. If undefined, then see if there are any
handlers registered at all.- Inherited From:
- See:
Returns:
- Type
- Boolean
-
invoke(obj)
-
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.Parameters:
Name Type Description objbaja.Action | String | Object the Action, Action name or object
literal for the method's arguments.Properties
Name Type Argument Description slotbaja.Action | String the Action or Action name.
value<optional>
the Action's argument.
okfunction <optional>
(Deprecated: use Promise) the ok callback. This
function is called once Action has been invoked. If the Action has a
returned argument, this will be passed to this function.failfunction <optional>
(Deprecated: use Promise) the fail callback.
This function is called if the Action fails to invoke. Any error
information is passed into this function.batchbaja.comm.Batch <optional>
if defined, any network calls will be
batched into this object.cx<optional>
the Context (used internally by BajaScript).
- Inherited From:
Returns:
a promise that will be resolved once
the Action has been invoked.- Type
- Promise.<(baja.Value|null)>
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); }); -
isMounted()
-
Return true if the
Componentis mounted inside a Space.- Inherited From:
Returns:
- Type
- Boolean
-
isNavChild()
-
Return true if this Component is a Nav Child.
- Inherited From:
Returns:
true if this Component is a Nav Child.
- Type
- Boolean
-
isSubscribed()
-
Is the component subscribed?
- Inherited From:
Returns:
- Type
- Boolean
-
lease( [obj])
-
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.Parameters:
Name Type Argument Description objNumber | baja.RelTime | Object <optional>
the number of milliseconds,
RelTime or an object literal for the method's arguments.Properties
Name Type Argument Description okfunction <optional>
(Deprecated: use Promise) the ok callback.
Called once the Component has been subscribed.failfunction <optional>
(Deprecated: use Promise) the fail callback.
Called if the Component fails to subscribe. Any errors will be passed to
this function.timeNumber | baja.RelTime <optional>
the number of milliseconds or
RelTime for the lease.batchbaja.comm.Batch <optional>
if defined, any network calls will be
batched into this object. The timer will only be started once the batch has
fully committed.- Inherited From:
- See:
Returns:
a promise that will be resolved once the component has
been subscribed.- Type
- Promise
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); }); -
loadSlots()
-
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.Parameters:
Name Type Argument Description obj.okfunction <optional>
(Deprecated: use Promise) the ok callback.
Called once the Component has been loaded.obj.failfunction <optional>
(Deprecated: use Promise) the fail callback.
Called if the Component fails to load. Any errors will be passed to this
function.obj.batchbaja.comm.Batch <optional>
if defined, any network calls will be
batched into this object.- Inherited From:
Returns:
a promise that will be resolved once the slots have
been loaded.- Type
- Promise
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); }); -
makeLink(obj)
-
Create an instance of a Link to use for a link to the specified source
Component.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.Parameters:
Name Type Description objObject the object literal for the method's arguments.
Properties
Name Type Argument Description sourcebaja.Component the source Component for the link.
sourceSlotbaja.Slot | String the source Slot or Slot name.
targetSlotbaja.Slot | String the target Slot or Slot name.
okfunction <optional>
(Deprecated: use Promise) the ok callback. A
Link will be passed as an argument to this function.failfunction <optional>
(Deprecated: use Promise) the fail callback.
batchbaja.comm.Batch <optional>
if defined, any network calls will be
batched into this object.- Inherited From:
Returns:
a promise that will be resolved with the
newly added Link.- Type
- Promise.<baja.Struct>
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); }); -
newCopy( [exact])
-
Create a clone of this
Complex.If the
exactargument is true and thisComplexis aComponentthen
thedefaultOnCloneandremoveOnCloneflags will be ignored.Parameters:
Name Type Argument Default Description exactBoolean <optional>
false flag to indicate whether to create an exact copy
- Inherited From:
Returns:
cloned Complex.
- Type
- baja.Complex
-
relations( [obj])
-
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.Parameters:
Name Type Argument Description objObject <optional>
the object literal for the method's arguments.
Properties
Name Type Argument Description okfunction <optional>
(Deprecated: use Promise) the ok callback. A
link will be passed as an argument to this function.failfunction <optional>
(Deprecated: use Promise) the fail callback.
batchbaja.comm.Batch <optional>
if defined, any network calls will be
batched into this object.- Inherited From:
Returns:
a promise that resolves
to the Component's relations.- Type
- Promise.<baja/tag/ComponentRelations>
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); }); -
remove(obj)
-
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.
Parameters:
Name Type Description objbaja.Slot | String | Object the Slot, Slot name,
Complex
instance or an object literal.Properties
Name Type Argument Description slotString the Slot, Slot name or
Complexinstance to
remove.okfunction <optional>
(Deprecated: use Promise) the ok callback. This
function is called once the Property has been removed from the Server.failfunction <optional>
(Deprecated: use Promise) the fail callback.
This function is called if the Property fails to remove. Any error
information is passed into this function.batchbaja.comm.Batch <optional>
if defined, any network calls will be
batched into this object.cx<optional>
the Context (used internally by BajaScript).
- Inherited From:
Returns:
a promise that will be resolved once the Property has
been removed.- Type
- Promise
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); }); -
rename(obj)
-
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.Parameters:
Name Type Description objObject the object literal used for the method's arguments.
Properties
Name Type Argument Description slotbaja.Slot | String the dynamic Slot or dynamic Slot name
that will be renamednewNameString the new name of the Slot. The name must meet
the "name" production in theSlotPathBNF grammar. Informally this means
that the name must start with an ASCII letter, and contain only ASCII
letters, ASCII digits, or '_'. Escape sequences can be specified using the
'$' char. Usebaja.SlotPath.escape()to escape illegal characters.okfunction <optional>
(Deprecated: use Promise) the ok callback. This
function is called once the Slot has been renamed.failfunction <optional>
(Deprecated: use Promise) the fail callback.
This function is called if the Slot fails to rename. Any error information
is passed into this function.batchbaja.comm.Batch <optional>
if defined, any network calls will be
batched into this object.cx<optional>
the Context (used internally by BajaScript).
- Inherited From:
Returns:
a promise that will be resolved once the slot has been
renamed.- Type
- Promise
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); }); -
reorder(obj)
-
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.Parameters:
Name Type Description objArray.<(baja.Property|String)> | Object the array of Properties
or Property names, or an object literal used for the method's arguments.Properties
Name Type Argument Description dynamicPropertiesArray.<(baja.Property|String)> an array of
Properties or Property names for the slot order.okfunction <optional>
(Deprecated: use Promise) the ok callback. This
function is called once the dynamic Properties have been reordered.failfunction <optional>
(Deprecated: use Promise) the fail callback.
This function is called if the dynamic Properties fail to reorder. Any
error information is passed into this function.batchbaja.comm.Batch <optional>
if defined, any network calls will be batched into this object.
cx<optional>
the Context (used internally by BajaScript).
- Inherited From:
Returns:
a promise that will be resolved once the dynamic
properties have been reordered.- Type
- Promise
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); }); -
rpc(methodName)
-
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.Parameters:
Name Type Description methodNameString The method name of the RPC call to invoke on
the Server.- Inherited From:
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)
-
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.Parameters:
Name Type Description objObject the object literal for the method's arguments.
Properties
Name Type Argument Description typeSpecString the type specification of the Server Side Call
Handler (moduleName:typeName).methodNameString the name of the method to invoke in the
Server Side Call Handlervaluethe value for the server side method argument (must be a
BajaScript Type)okfunction <optional>
(Deprecated: use Promise) the ok callback.
Called once the Server Side Call has been invoked. Any return value is
passed to this function.failfunction <optional>
(Deprecated: use Promise) the fail callback.
Called if the Component fails to load. Any errors will be passed to this
function.batchbaja.comm.Batch <optional>
if defined, any network calls will be
batched into this object.- Inherited From:
Returns:
a promise that will be resolved once
the server side call has completed.- Type
- Promise.<(baja.Value|null)>
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); }); -
set(obj)
-
Set a
Property's value.If the Complex is mounted, this will asynchronously set the Property's
value on the Server.Parameters:
Name Type Description objObject the object literal for the method's arguments.
Properties
Name Type Argument Description slotbaja.Property | String the
Propertyor Property name
the value will be set on.valuethe value being set (Type must extend
baja:Value).okfunction <optional>
(Deprecated: use Promise) the ok function
callback. Called once the network call has succeeded on the Server.failfunction <optional>
(Deprecated: use Promise) the fail function
callback. Called if this method has an error.batchbaja.comm.Batch <optional>
if defined, any network calls will be
batched into this object.cx<optional>
the Context (used internally by BajaScript).
- Inherited From:
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
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'); }); -
setFacets(obj)
-
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.Parameters:
Name Type Description objObject the object literal for the method's arguments.
Properties
Name Type Argument Description slotbaja.Slot | String the Slot of Slot name.
facetsbaja.Facets the new facets for the dynamic Slot.
okfunction <optional>
(Deprecated: use Promise) the ok function
callback. Called once the method has succeeded.failfunction <optional>
(Deprecated: use Promise) the fail function
callback. Called if this method has an error.batchbaja.comm.Batch <optional>
if defined, any network calls will be
batched into this object.cx<optional>
the Context (used internally by BajaScript).
- Inherited From:
Returns:
a promise that will be resolved once the Facets have
been set.- Type
- Promise
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); }); -
setFlags(obj)
-
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.Parameters:
Name Type Description objObject the object literal for the method's arguments.
Properties
Name Type Argument Description slotbaja.Slot | String the Slot or Slot name.
flagsNumber the new flags for the Slot.
okfunction <optional>
(Deprecated: use Promise) the ok function
callback. Called once the method has succeeded.failfunction <optional>
the fail function callback. Called if this
method has an error.batchbaja.comm.Batch <optional>
if defined, any network calls will be
batched into this object.cx<optional>
the Context (used internally by BajaScript).
- Inherited From:
Returns:
a promise that will be resolved once the flags have been
set.- Type
- Promise
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); }); -
tags(obj)
-
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.Parameters:
Name Type Description objObject the object literal for the method's arguments.
Properties
Name Type Argument Description okfunction <optional>
(Deprecated: use Promise) the ok callback. A
collection of tags will be passed as an argument to this function.failfunction <optional>
(Deprecated: use Promise) the fail callback.
batchbaja.comm.Batch <optional>
if defined, any network calls will be
batched into this object.- Inherited From:
Returns:
a promise that resolves
to the Component's tags.- Type
- Promise.<module:baja/tag/ComponentTags>
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); }); -
toPathString()
-
Return the path string of the
Component.- Inherited From:
Returns:
the Path String or null if not mounted.
- Type
- String
-
toString()
-
Return the
Stringrepresentation.- Inherited From:
Returns:
- Type
- String
-
valueOf()
-
Return the inner value of the object.
By default the object's instance is returned.
- Inherited From:
Returns:
the inner value of the object or just the object's instance.
- Type
- *