afterCount( )
A hook that is triggered after a count()
operation.
Description
The afterCount()
hook runs when:
- The
count()
function is called. - The collection is viewed in the CMS.
Return a number or a Promise that resolves to number from the afterCount()
function. The returned number will be used as the result of the call to
count()
instead of the actual count of
items found in the collection. If returning a Promise, the number 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.
Syntax
function afterCount(count: number, context: HookContext): Promise<number> | number
afterCount Parameters
NAME
TYPE
DESCRIPTION
The number of items the count operation has found.
Contextual information about the hook.
Returns
The count to return to count()
instead of the original count.
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:
|
numberWas this helpful?
1// In data.js23export function myCollection_afterCount(count, context) {4 let hookContext = context; // see below56 // some change to the received count78 return count;9}1011/*12 * hookContext:13 *14 * {15 * "collectionName": "myCollection",16 * "userId": "f45jf8d2-grkj-2opd-4ovk-9rfj4wo5tvj3",17 * "userRole": "siteOwner"18 * }19 */
count()
using an afterCount hook1// In data.js23export function myCollection_afterCount(count, context) {4 let hookContext = context; // see below56 // return a value higher than the actual item count7 count += 5;89 return count;10}1112/*13 * hookContext:14 *15 * {16 * "collectionName": "myCollection",17 * "userId": "f45jf8d2-grkj-2opd-4ovk-9rfj4wo5tvj3",18 * "userRole": "siteOwner"19 * }20 */