equals
import { equals } from 'patronum';// orimport { equals } from 'patronum/equals';Motivation
The method allows to compare store value with another value wrote as literal or contained in another store.
Formulae
$isEquals = equals(first, second);$isEqualswill be store withtrueif value infirstandsecondis equals by comparing them with===
Arguments
first: Store<T> | T— A value or the store to compare withsecondsecond: Store<T> | T— A value or the store to be compared withfirst
Returns
$isEquals: Store<boolean>— The store containstrueif values is equals
Example
const $first = createStore('foo bar');const $isEquals = equals($first, 'foo bar');
console.assert(true === $isEquals.getState());Composition
The equals operator can be composed with any other method of patronum:
const $account = createStore<Account | null>(null);const $authorized = not(equals($account, null));// $authorized contains `true` only when $account contains not `null`Alternative
Compare to literal value:
import { createStore } from 'effector';const $first = createStore('foo bar');const $isEquals = $first.map((first) => first === 'foo bar');
console.assert(true === $isEquals.getState());Compare to another store:
import { createStore, combine } from 'effector';const $first = createStore('foo bar');const $second = createStore('foo bar');const $isEquals = combine($first, $second, (first, second) => first === second);
console.assert(true === $isEquals.getState());