/
githubmirror
/
immutable-js
Обзор
Документация
Войти
/
githubmirror
/
immutable-js
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
v4.3.3
src/utils/deepEqual.js
73 строки
2 KB
Lee Byron
Upgrade Prettier (#1817)
18 июн 2021, 02:30
Не верифицирован
18 июн 2021, 02:30
c02d769
Код
Авторство
О чём код?
import { is } from '../is'; import { NOT_SET } from '../TrieUtils'; import { isCollection } from '../predicates/isCollection'; import { isKeyed } from '../predicates/isKeyed'; import { isIndexed } from '../predicates/isIndexed'; import { isAssociative } from '../predicates/isAssociative'; import { isOrdered } from '../predicates/isOrdered'; export default function deepEqual(a, b) { if (a === b) { return true; } if ( !isCollection(b) || (a.size !== undefined && b.size !== undefined && a.size !== b.size) || (a.__hash !== undefined && b.__hash !== undefined && a.__hash !== b.__hash) || isKeyed(a) !== isKeyed(b) || isIndexed(a) !== isIndexed(b) || isOrdered(a) !== isOrdered(b) ) { return false; } if (a.size === 0 && b.size === 0) { return true; } const notAssociative = !isAssociative(a); if (isOrdered(a)) { const entries = a.entries(); return ( b.every((v, k) => { const entry = entries.next().value; return entry && is(entry[1], v) && (notAssociative || is(entry[0], k)); }) && entries.next().done ); } let flipped = false; if (a.size === undefined) { if (b.size === undefined) { if (typeof a.cacheResult === 'function') { a.cacheResult(); } } else { flipped = true; const _ = a; a = b; b = _; } } let allEqual = true; const bSize = b.__iterate((v, k) => { if ( notAssociative ? !a.has(v) : flipped ? !is(v, a.get(k, NOT_SET)) : !is(a.get(k, NOT_SET), v) ) { allEqual = false; return false; } }); return allEqual && a.size === bSize; }