Function Node
Functions allow you to perform actions within Dynaboard.
When creating a function, you'll specify both a resource and action on that resource you would like to have performed. From there, Dynaboard will walk you through configuring the action. You can use binding expressions in almost any field within the function editor. Wire up function nodes using event handlers, chain them together, or invoke them programmatically.
Functions are designed to be lightweight and flexible, so create as many as you'd like. Evaluation of the function is resource and action type-dependent, but the results are always the same: data
, error
, and extra
.
Using functions
Functions must be invoked explicitly, either on page load, via an event handler, or programmatically.
Calling on page load
Set the "Run on page load" property (runOnPageLoad
) to true
to run the function on page load.
Calling via event handlers
Functions can be used as event handlers to perform actions when something occurs within the application.
Within the Events tab of any element, you can select your function from the dropdown menu. Simple as that!
Calling programmatically
You can invoke functions programmatically using the TypeScript Client Resource (opens in a new tab). All invocations return a Promise
value, so you'll have to await
them before using their results.
For example, if you have a function named myFunction
, you can invoke it by doing:
const { data, error, extra } = await myFunction()
// do what you need to do...
return data
Evaluation semantics
Dynaboard transparently handles both client-side and server-side evaluated function. Whether or not a function is server-side or client-side depends on the resource to which it is attached.
Server-side functions
For server-side functions, Dynaboard will take care of generating a parameterized API for you if you use binding expressions.
Dynaboard acts as a proxy, returning the results back to the client. Any TypeScript code that appears in {{ double_curlies }}
will be evaluated client-side before being serialized and sent to the server. The Dynaboard server will handle interpolating these values into your functions.
Client-side functions
For client-side functions, Dynaboard evaluates the entire function server-side without making an intermediate call to the Dynaboard server.
Properties
Enabled
Prop | isEnabled |
---|---|
Type | boolean |
Default | true |
Whether or not this function is runnable
Data
Prop | data |
---|---|
Type | unknown |
Default | undefined |
The latest data returned by the function after transform. Every resource / action type will populate this value differently, so consult the resource's documentation for more information about the shape of this property.
Raw Data
Prop | rawData |
---|---|
Type | unknown |
Default | undefined |
The latest raw data returned by the function. Every resource / action type will populate this value differently, so consult the resource's documentation for more information about the shape of this property
Error
Prop | error |
---|---|
Type | unknown |
Default | undefined |
The latest error message thrown by the function. If no error was returned (such as in the case of a successful evaluation), this will be undefined
.
Extra
Prop | extra |
---|---|
Type | unknown |
Default | undefined |
The latest extra metadata returned by the function. Every resource / action type will populate this value differently, so consult the resource's documentation for more information about the shape of this property.
Loading
Prop | loading |
---|---|
Type | boolean |
Default | false |
Whether or not the function is currently executing or awaiting results
Action
Prop | action |
---|---|
Type | object |
Default | { 'targetNode': {} } |
The specification for the action to be evaluated when the function is called. Actions are defined by a reference to a resource and an action on that resource, along with any other properties required by that action.
Target node
Prop | action.targetNode |
---|---|
Type | object |
Default | undefined |
The node to which this action is attached
Ref
Prop | action.targetNode.ref |
---|---|
Type | string |
Default | undefined |
The id of the target node
Action type
Prop | action.actionType |
---|---|
Type | string |
Default | undefined |
The name of the selected action
Run Function
Prop | callingSemantics |
---|---|
Type | FunctionRunType ('IMPERATIVE' | 'REACTIVE') |
Default | IMPERATIVE |
Functions can be run when called via an event handler, on page load (if specified), or from another function. Automatically-run functions run on page load, and then again every time the function or any of its dependent properties change.
Limiter Type
Prop | debounceMethod |
---|---|
Type | DebounceMethod ('NONE' | 'DEBOUNCE' | 'THROTTLE') |
Default | DEBOUNCE |
Debounce waits until the specified number of milliseconds has elapsed since the last change before triggering the function. Throttle triggers the function as soon as there is a change, and then will not trigger again until there has been the specified number of milliseconds since it last triggered. None will trigger the function on every change.
Limiter Timing
Prop | debounceMillis |
---|---|
Type | number |
Default | 0 |
The amount of time in milliseconds to consider for the debounce method above
On Load
Prop | runOnPageLoad |
---|---|
Type | boolean |
Default | false |
Whether or not to automatically run the function upon page load. If false (the default), the function will not be invoked until explicitly called by an event handler.
Authorization Rules
Prop | authorizationRules |
---|---|
Type | string |
Default | [] |
Custom authorization rules for this function
Transformer
Prop | transformer |
---|---|
Type | string |
Default | undefined |
Typescript code to transform the rawData and output
Event Handlers
On Success
Handler | functionNode.onSuccess |
---|
The event handler to be called upon the successful completion of the function. This property can be used to chain function calls.
On Failure
Handler | functionNode.onFailure |
---|
The event handler to be called upon the failure of the function. This property can be used to handle errors in function calls.