Skip to content

Amend

The object that a should… hook returns to replace a change by another one, instead of accepting it or refusing it. The app then continues with the replacement, as if the original change had never been proposed.

The replacement is a ChangeDraft, which is an object whose deltas property lists the modifications to apply. A hook usually builds it by copying the draft that it received and altering some of its deltas.

A plugin can replace a change once, and only for things that belong to the plugin. Replacing anything else requires the amend:outside permission. A plugin builds this object with amend(proposal, note?).

// the hook receives a draft, copies it with one delta altered, and returns the copy
ctx.hooks.shouldUpdate({}, draft => {
const deltas = draft.deltas.map(alterOneDelta);
return amend({ ...draft, deltas }, 'Altered one delta');
});
Type Parameter Description
P the type of the replacement. For the hooks of ctx.hooks, it is ChangeDraft.
readonly amend: P;

The replacement: a ChangeDraft, whose deltas property lists the modifications to apply instead of the original ones.


readonly note?: string;

An optional explanation of why the change was replaced. The app keeps it in the diagnostics of the plugin.