and
import { and } from 'patronum';// orimport { and } from 'patronum/and';
Motivation
The method allows to check each passed store for thruthy values.
It can be compared with if (a && b && c && d)
.
Formulae
$result = and(...stores);
$result
store containstrue
if each passed store contains “truthy” values.
Arguments
The method receives any amount of arguments.
...stores: Array<Store<T>>
— Each argument must be store with a value of any kind.
Returns
$result: Store<boolean>
— The store containsfalse
if at least one passed store instores
contains “falsey” value
Example
const $isAuthorized = createStore(true);const $isAdmin = createStore(false);const $orderFinished = createStore(true);
const $showCancelButton = and($isAuthorized, $isAdmin, $orderFinished);console.assert(false === $showCancelButton.getState());
Composition
const $showRegisterLink = and( not($isAuthorized), or($isRegisterInProcess, $isEmailRecovering),);
Alternative
const $showRegisterLink = combine( $isAuthorized, $isRegisterInProcess, $isEmailRecovering, (isAuthorized, isRegisterInProcess, isEmailRecovering) => { return !isAuthorized && (isRegisterInProcess || isEmailRecovering); },);console.assert(false === $showRegisterLink.getState());