Nova · Shells
Hooks
An action is told when it is put on a canvas, covered, uncovered and taken off: mount, suspend, resume, unmount. Here the first action writes down each one as it happens. Uncovered, it is told mount again and then resume, so what it loads on mount is never stale.
{
canvases: [{ id: 'hooks.main', initial: 'hooks.first' }],
actions: {
hooks.first: {
id: 'hooks.first',
data: { seen: [] },
layout: {
component: 'Stack',
children: [
{
for: '$.seen',
as: 'hook',
do: { component: 'Text', children: '$hook' },
},
{
component: 'Button',
ref: 'cover',
children: 'Open another on top',
},
],
},
lifecycle: {
mount: [{ push: 'seen', value: 'mount' }],
suspend: [{ push: 'seen', value: 'suspend' }],
resume: [{ push: 'seen', value: 'resume' }],
},
triggers: [
{
event: 'ui:click',
ref: 'cover',
do: [{ push: { action: 'hooks.second' } }],
},
],
},
hooks.second: {
id: 'hooks.second',
layout: { component: 'Button', ref: 'back', children: 'Back' },
triggers: [{ event: 'ui:click', ref: 'back', do: [{ pop: true }] }],
},
},
}mount
press cover press back
{ hooks.main: ['hooks.first'] }mount suspend mount resume Open another on top
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.