Custom Plugin
Explanation #
Custom actions, attributes, and watchers can be implemented using the plugin API. This example implements a simple alert action and attribute.
Action #
An action
plugin can be implemented as follows.
Setting the name
to alert
results in the syntax @alert
.
Attribute #
An attribute
plugin can be implemented as follows.
Setting the name
to alert
results in the syntax data-alert
.
The attribute shouldn’t take a key and needs a value, so key
is denied
and value
is a must
. The attribute expects a value to be returned from the expression so we set returnsValue
to true
.
On apply, we create an event listener that alerts the value returned from the expression when the element is clicked. We return a function that removes the event listener on cleanup.