Nova · Endpoints

Function endpoint

An endpoint that names a function its host has registered. call runs it with the action’s data, and what it answers is written to the endpoint’s target.

The action, as it is written
{
  id: 'function-endpoint',
  data: { total: { seats: 0, price: 0 } },
  layout: {
    component: 'Stack',
    children: [
      {
        component: 'Text',
        children: '{{$.total.seats}} seats, {{$.total.price}} in all',
      },
      {
        component: 'Button',
        ref: 'add',
        children: 'Add it up',
      },
    ],
  },
  endpoints: {
    total: { fn: 'function-endpoint.total', target: 'total' },
  },
  triggers: [
    {
      event: 'ui:click',
      ref: 'add',
      do: [{ call: 'total' }],
    },
  ],
}
Running herepress it

0 seats, 0 in all

What its endpoints are answered
{ function-endpoint.total: { seats: 3, price: 114 } }
What is done to it
press add
What it then holds
{ total: { seats: 3, price: 114 } }
What it then says
3 seats, 114 in all
Add it up
Output matches the expected value

Left: the action as the package ships it. Right: the same action running in this page, rendered with this site’s components. Below: the action run as the example specifies, on the installed package.