empty (experimental)
since
patronum 1.10.0
experimental
Operator is going to be renamed. Please review the discussion.
import { empty } from 'patronum';
// or
import { empty } from 'patronum/empty';
Motivation
The method allows to check passed value for null
.
Sometimes you need just to check for nullability, and go on.
Formulae
$result = empty($value);
$result
store containstrue
if$value
store containsnull
Arguments
$value: Store<T | null>
— The store contains any kind of value.
Returns
$result: Store<boolean>
— The store containsfalse
if passed$value
store contains any kind of value other fromnull
Example
const $account = createStore<Account | null>(null);
const $anonymous = empty($account);
const $authorized = not($anonymous);
console.assert(true === $anonymous.getState());
console.assert(false === $authorized.getState());
Alternative
import { createStore } from 'effector';
const $account = createStore<Account | null>(null);
const $anonymous = $account.map((account) => account === null);
const $authorized = $anonymous.map((anonymous) => !anonymous);
console.assert(true === $anonymous.getState());
console.assert(false === $authorized.getState());