xor
import { xor } from 'patronum';// orimport { xor } from 'patronum/xor';Motivation
Combines multiple stores, returning true if exactly one of them is truthy.
Formulae
$result = xor($first, $second);$resultwill betrue, if exactly one of the stores is truthy$resultwill befalse, if all stores are falsy or more than one store is truthy
Arguments
The method receives any amount of arguments.
stores: Array<Store<any>>— Any number of stores to check through XOR
Returns
$result: Store<boolean>— The store containstrueif exactly one of the passed stores is truthy, otherwisefalse
Example
Basic usage
import { createStore } from 'effector';import { xor } from 'patronum/xor';
const $isOnline = createStore(true);const $isProcessing = createStore(false);
const $isDisabled = xor($isOnline, $isProcessing);console.assert(true === $isDisabled.getState());// $isDisabled === true, because $isOnline === true and $isProcessing === false
const $hasError = createStore(true);const $result = xor($isOnline, $isProcessing, $hasError);console.assert(false === $result.getState());// $result === false, because multiple stores are truthy ($isOnline and $hasError)