Recent Changes - Search:

edit SideBar


An accessor may specify parameters in the body of the setup() function by invoking:

  • parameter(<string> name, [options]): Create the parameter. Options are optional.

A parameter, unlike an input, is not expected to change value during the execution of a swarmlet. NOTE: Perhaps it should be required that whenever a parameter value is changed, the setup() function is re-executed. This could be useful, for example, if the possible values of one parameter depend on the value of another parameter.

For example, the following accessor will send the value of the foo parameter to its output bar once:

  exports.setup = function() {
    parameter('foo', {'value':'y', 'type':'string'});
  exports.initialize = function() {
    send('bar', getParameter('foo'));

The parameter() function takes one or two arguments, a name (a required string, recommended to be camelCase with a leading lower-case character) and an object with any of the following options:

typeThe data type of the parameter. If this is not specified, then any valid JavaScript value may be provided as a value. If it is specified, it must be one of the valid data types.
valueThe default value for the parameter. Specifying a default value ensures that getParameter() will not return null (see below).
optionsAn array of possible values for this parameter. A user interface may list these possible values, and a host may restrict the values to be one of these values.
visibilityA hint to the host of whether this parameter should be made visible to casual users. This is a string that is one of "full", "none", "expert", or "notEditable", meaning "full visibility", "no visibility", "expert visibility", or "visible, but not editable". This option is useful for accessors that extend other accessors but do not want to make the parameters of the base accessor visible in the derived accessor.

The name is required to be distinct from other inputs, outputs, and parameters. It may match the name of a parameter in a base accessor (specified by either extend() or implement()), in which case the options will override those specified in the base.

Getting Parameters

The current value of a parameter may be retrieved in the accessor's JavaScript code using the getParameter() function, as in the following example:

    var address = getParameter('bridgeIPAddress');

The getParameter() function takes one argument, the parameter name (as a string).

If no value option is given, then getParameter() will return null if the host has not provided a parameter value.

Setting Parameters

The current value of a parameter may be set in the accessor's JavaScript code using the setParameter() function, as in the following example:

    setParameter('bridgeIPAddress', '');

This might be done, for example, in an accessor that extends another to change the default value of the parameter.

See Also

Back to accessor specification

Edit - History - Print - Recent Changes - Search
Page last modified on December 29, 2015, at 06:16 PM