afterRemove( )
A hook that is triggered after a remove()
operation.
Description
The afterRemove()
hook runs when:
- The
remove()
function is called. - An action is performed on a dataset that removes an item from the collection.
- An item is deleted using the CMS.
Return an object or a Promise that resolves to an object. The returned object
will be used as the result of the call to the remove()
function instead of the actual item removed from the collection. If returning a
Promise, the object is used as the result, whether the Promise is fulfilled or rejected.
If the returned value is of the wrong type, the value is ignored.
A rejected Promise also calls the onFailure()
hook if it has
been registered.
Because the afterRemove()
hook is called after the remove()
is executed, it cannot prevent the item from being removed from the collection.
It can only affect the item returned by remove()
.
Syntax
function afterRemove(item: Object, context: HookContext): Promise<Object> | Object
afterRemove Parameters
NAME
TYPE
DESCRIPTION
The item that was removed.
Contextual information about the hook.
Returns
The item to return to remove()
instead of the deleted item.
Returning a rejected promise will not block the operation, but will return a rejected promise to the caller as well as trigger the onFailure()
hook.
Return Type:
|
ObjectWas this helpful?
1// In data.js23export function myCollection_afterRemove(item, context) {4 let hookContext = context; // see below56 // some changes to the removed item78 return item;9}1011/*12 * hookContext:13 *14 * {15 * "collectionName": "myCollection",16 * "userId": "f45jf8d2-grkj-2opd-4ovk-9rfj4wo5tvj3",17 * "userRole": "siteOwner"18 * }19 */
remove()
using an afterRemove hook1// In data.js23export function myCollection_afterUpdate(item, context) {4 let hookContext = context; // see below56 // add a full_name property to the item being returned7 item.full_name = item.first_name + " " + item.last_name;89 return item;10}1112/*13 * hookContext:14 *15 * {16 * "collectionName": "myCollection",17 * "userId": "f45jf8d2-grkj-2opd-4ovk-9rfj4wo5tvj3",18 * "userRole": "siteOwner"19 * }20 */