iff
See also: iffElse unless predicates
Execute one or another series of hooks depending on a sync or async predicate.
import { iff } from 'feathers-utils/hooks';Type declaration
export interface IffHook<H extends HookContext = HookContext>
extends HookFunction<H> {
else(...hooks: HookFunction<H>[]): HookFunction<H>
}
/**
* Execute one or another series of hooks depending on a sync or async predicate.
*
* @see https://utils.feathersjs.com/hooks/iff.html
*/
export declare function iff<H extends HookContext = HookContext>(
predicate: boolean | PredicateFn<H>,
...hooks: HookFunction<H>[]
): IffHook<H>
export { iff as when }| Argument | Type | Description |
|---|---|---|
| predicate | boolean | PredicateFn<H> | |
| hooks | HookFunction<H>[] |
| type | methods | multi |
|---|---|---|
| before, after | all | yes |
Predicates
'feathers-utils' provides a set of predicates that can be used with this hook. These predicates can be used to conditionally execute hooks based on the result of a predicate function.
everyReturn the and of a series of sync or async predicate functions.
isContextCheck if the context matches the given options.
isMultiutil to check if a hook is a multi hook:
- find: true
- get: false
- create:
context.datais an array - update: false
- patch:
context.id == null - remove:
context.id == null
isPaginatedutil to check if a hook is a paginated hook using getPaginate
isProviderCheck which transport provided the service call.
notNegate a predicate function.
shouldSkipUtil to detect if a hook should be skipped
Checks the params.skipHooks array for the hook name, type, or 'all'.
someReturn the or of a series of sync or async predicate functions.
