# Handlers
Handlers are JavaScript functions you can define in the graph in order to use them in the Live Properties instructions.
Handlers are stored in a special Live Attribute (live.handlers) in the graph root, like Refresh.
You can access defined handlers in Live Properties values with handlers
argument, where each handler is stored with its name as object parameter.
Ex: = return handlers.getWeatherLabel(data.weather.status);
Computes Live Property updated value according to:
- Data fetched in the object stored by the Live node with API ID equal to
weather
- Handler named
getWeatherLabel
Handlers methods are stored in Handlers as pairs of key & value.
# Key
Key of a handler pair is its name, mandatory to make the defined handler accessible for Live Properties inside handlers object.
WARNING
Each handler name must be unique.
Be careful, if a new defined handler shares an old one's name, it deletes it.
# Value
Value of a handler pair is a fully defined JavaScript function.
There is no limit to the number of arguments the function can take.
Function body boundaries are marked by { }
& instructions are separated by ;
.
Function MUST return something, otherwise the handler is useless.
There are 2 ways to write a function:
Classic function
function(...args) { /*...instructions; return;*/ }
Arrow function
(...args) => { /*...instructions; return;*/ }
- In case of only 1 argument, ( ) are not required
Ex: x => { ... } === (x) => { ... }
- In case of only 1 instruction, neither { } scope delimiters nor return keyword are required
Ex: (a, b) => { return a+b;} === (a, b) => a+b;
WARNING
(a, b) => a+b; !== (a, b) => { a+b;}
In the second case handler does not return anything.
A warning is thrown on the UI if a handler is not well-formed.