Skip to content

defer

function defer<P>(promise, reason): Defer<P>;

Asks the app to wait for an answer that is not known yet, for example the reply of the person to a question. The app waits, and the screen keeps working. If the library changes while the app waits, the app checks the change again before it applies it.

Type Parameter Description
P the type of the replacement that an Amend decision carries. For the hooks of ctx.hooks, it is ChangeDraft
Parameter Type Description
promise Promise<Decision<P>> a promise of the decision to take: allow(), veto(…) or amend(…)
reason string what the app is waiting for

Defer<P>

{ defer: promise, reason }

// when a change deletes more than 30 rows, ask the person first (needs the permission `ui`)
ctx.hooks.shouldUpdate({}, proposal => {
const deleted = proposal.deltas.filter(d => d.kind === 'deleted' && d.ref.kind === 'row').length;
if (deleted <= 30) return allow();
return defer(
ctx.ui.confirm({ title: `Delete ${deleted} rows?`, message: 'This can be undone.' })
.then(answer => (answer.confirmed ? allow() : veto('cancelled', 'Not deleted'))),
'Confirming',
);
});