amend
function amend<P>(proposal, note?): Amend<P>;Replaces the change by another one, instead of accepting it or refusing it. A plugin can do this once per change, and only for things that belong to the plugin. Replacing anything else requires the amend:outside permission.
Type Parameters
Section titled “Type Parameters”| Type Parameter | Description |
|---|---|
P |
the type of the replacement. For the hooks of ctx.hooks, it is ChangeDraft |
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
proposal |
P |
the replacement: a ChangeDraft, which is an object whose deltas property lists the modifications to apply instead of the original ones |
note? |
string |
an optional explanation of why the change was replaced, which is kept in the diagnostics of the plugin |
Returns
Section titled “Returns”Amend<P>
{ amend: proposal, note }
Example
Section titled “Example”// remove the spaces at the start and at the end of every title that is edited.// The rows do not belong to the plugin, so this requires the `amend:outside` permission.ctx.hooks.shouldUpdate({}, draft => { const deltas = draft.deltas.map(d => d.kind === 'updated' && typeof d.after.title === 'string' ? { ...d, after: { ...d.after, title: d.after.title.trim() } } : d); return amend({ ...draft, deltas }, 'Trimmed the title');});