/
githubmirror
/
immutable-js
Обзор
Документация
Войти
/
githubmirror
/
immutable-js
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
website/docs/ValueObject.mdx
49 строк
2 KB
Julien Deniau
Doc as mdx instead of export from .d.ts file (#2104)
24 май 2025, 00:47
Не верифицирован
24 май 2025, 00:47
21de701
Код
Авторство
О чём код?
import Repl from '@/repl/Repl.tsx'; import CodeLink from '@/mdx-components/CodeLink.tsx'; # ValueObject The interface to fulfill to qualify as a Value Object. ## Members <MemberLabel label="equals" /> True if this and the other Collection have value equality, as defined by `Immutable.is()`. <Signature code="equals(other: unknown): boolean;" /> Note: This is equivalent to `Immutable.is(this, other)`, but provided to allow for chained expressions. <MemberLabel label="hashCode" /> Computes and returns the hashed identity for this Collection. <Signature code={`hashCode(): number;`} /> The `hashCode` of a Collection is used to determine potential equality, and is used when adding this to a `Set` or as a key in a `Map`, enabling lookup via a different instance. <Repl defaultValue={`const a = List([1, 2, 3]); const b = List([1, 2, 3]); // a and b are different instances const set = Set([a]); set.has(b)`} /> Note: hashCode() MUST return a Uint32 number. The easiest way to guarantee this is to return `myHash | 0` from a custom implementation. If two values have the same `hashCode`, they are [not guaranteed to be equal][Hash Collision]. If two values have different `hashCode`s, they must not be equal. Note: `hashCode()` is not guaranteed to always be called before `equals()`. Most but not all Immutable.js collections use hash codes to organize their internal data structures, while all Immutable.js collections use equality during lookups. [Hash Collision]: https://en.wikipedia.org/wiki/Collision_(computer_science)