Version1 /
ActionFunctions(redirected from VersionCurrent.ActionFunctions) An accessor may define some number of action functions that are invoked by the host as described below. The only required function is the setup() function. An accessor may implement any subset of the rest. These functions are made available to the host by setting them as fields of the exports object in the accessor script with the corresponding name. For instance, the exports.initialize = function() { console.log('Hello World!'); } An execution of an accessor consists of:
fire()If provided, the host will invoke this function when any new input is provided, or if there are no inputs at all, then whenever the host chooses to invoke it. initialize()This function, if provided, will be invoked once by the host when the application using the accessor starts up, and possibly again each time the swarmlet is re-initialized. The accessor may get any inputs that have default values, read parameters, and initialize state variables. It may also send outputs, but note that downstream accessors will not see this data in their initialize function. They will see it in an input handler, if they have registered one. Input handlersAn input handler is a function that is invoked when a new input arrives. See Input Handlers. latestOutput(name)Return the most recent output sent via the named output. provideInput(name, value)Provide the specified input with the specified value. react()React to any provided inputs by invoking any associated input handlers and also invoking the fire() function, if there is one. setParameter(name, value)Set the specified parameter to have the specified value. setup()Set up the actor interface, defining inputs, outputs, and parameters. wrapup()If provided, the host will invoke this function once when the application shuts down. This function should not send outputs. DiscussionWith these action functions, there is a variety of patterns of accessor behavior:
Note that it is an error to send outputs before the host has invoked initialize or after it has invoked Note also that action functions are called "functions" even though they are not mathematical functions, because JavaScript calls them functions. They may have side effects. Back to Accessor Specification |