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?).
Example
Section titled “Example”// the hook receives a draft, copies it with one delta altered, and returns the copyctx.hooks.shouldUpdate({}, draft => { const deltas = draft.deltas.map(alterOneDelta); return amend({ ...draft, deltas }, 'Altered one delta');});Type Parameters
Section titled “Type Parameters”| Type Parameter | Description |
|---|---|
P |
the type of the replacement. For the hooks of ctx.hooks, it is ChangeDraft. |
Properties
Section titled “Properties”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.
