Recent Changes - Search:

edit SideBar



An accessor may define any number of outputs in the body of its setup() function using

  • output(<string> name, [options]): Create an output with the specified name and options.

For example:

 exports.setup = function() {
     output('price', {

The output() 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 output. If this is not specified, then any valid JavaScript value may be sent to the output. If it is specified, it must be one of the valid data types.
spontaneoustrue or false. A spontaneous output is produced by an asynchronous callback rather than as a response to an input. Every directed cycle in a connectivity graph must contain at least one spontaneous output or there will be a deadlock due to a causality loop.

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

Sending to Outputs

An accessor may use the send() function to send values via its output ports. This may be done in a callback function, such as a function passed to setTimeout or addInputHandler (see Top-Level Java Script Functions). For example, suppose that the following line is executed in a callback:

    send('price', 42);

This will send the number 42 to the price output. If you send a null value to an output, and that output is connected to an input x of a downstream accessor, then that accessor's input handler will get null when it invokes get('x').

Note that if the output data type is JSON, then the JavaScript value will be converted to a JSON string before sending. This can be confusing. Specifically, if you want to send, say, {"foo": 42}, then you should do

    send('output', {"foo": 42});

and not

    send('output', '{"foo": 42}');

In other words, do not convert your object to a JSON string yourself.

See Also

Back to accessor specification

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