iffElse
See also: iff unless predicates
Execute one array of hooks or another based on a sync or async predicate.
ts
import { iffElse } from 'feathers-utils/hooks';Type declaration
ts
/**
* Execute one array of hooks or another based on a sync or async predicate.
*
* @see https://utils.feathersjs.com/hooks/iff-else.html
*/
export declare function iffElse<H extends HookContext = HookContext>(
predicate: boolean | PredicateFn<H>,
trueHook: HookFunction<H> | HookFunction<H>[] | undefined,
falseHook?: HookFunction<H> | HookFunction<H>[] | undefined,
): (this: any, ctx: H) => any| Argument | Type | Description |
|---|---|---|
| predicate | boolean | PredicateFn<H> | |
| trueHook | HookFunction<H> | HookFunction<H>[] | undefined | |
| falseHook | HookFunction<H> | HookFunction<H>[] | undefined |
| 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.
