1.0.2 • Published 9 years ago
ember-changeset-hofs v1.0.2
ember-changeset-hofs
Higher-order validation functions for ember-changeset-validations.
For background info, please see the thread here.
This addon provides and and or higher-order functions, that allow you to
compose together validations. It is useful if you want the short-circuit
behavior of && and ||. For example:
// app/validations/user.js
import and from 'ember-changeset-hofs/utils/and'
import or from 'ember-changeset-hofs/utils/or'
export const {
email: and(
validateFormat({ type: 'email' }),
askServerIfExists(), // will not get called if validateFormat fails
),
anotherEmail: or(
isUndefinedOrNull(),
askServerIfExists(), // will not get called if isUndefinedOrNull succeeds
),
}Note that the and and or utils work with both synchronous and asynchronous
validators. You can nest and and or expressions arbitrarily, and you can
mix sync and async validators however you want:
const validationFn = and(
and(
and(...someValidators),
or(...someMoreValidators),
or(
or(...someValidators),
and(...someMoreValidators),
)
),
or(...evenMoreValidators)
)Install
$ ember install ember-changeset-hofsLicense
MIT