MCPcopy
hub / github.com/tldraw/tldraw / ArrayMapNode

Class ArrayMapNode

packages/store/src/lib/ImmutableMap.ts:464–540  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

462// #pragma Trie Nodes
463
464class ArrayMapNode<K, V> {
465 constructor(
466 public ownerID: OwnerID,
467 public entries: Array<[K, V]>
468 ) {}
469
470 get(_shift: unknown, _keyHash: unknown, key: K, notSetValue?: V) {
471 const entries = this.entries
472 for (let ii = 0, len = entries.length; ii < len; ii++) {
473 if (Object.is(key, entries[ii][0])) {
474 return entries[ii][1]
475 }
476 }
477 return notSetValue
478 }
479
480 update(
481 ownerID: OwnerID,
482 _shift: unknown,
483 _keyHash: unknown,
484 key: K,
485 value: V,
486 didChangeSize?: Ref,
487 didAlter?: Ref
488 ): MapNode<K, V> | undefined {
489 const removed = value === NOT_SET
490
491 const entries = this.entries
492 let idx = 0
493 const len = entries.length
494 for (; idx < len; idx++) {
495 if (Object.is(key, entries[idx][0])) {
496 break
497 }
498 }
499 const exists = idx < len
500
501 if (exists ? entries[idx][1] === value : removed) {
502 return this
503 }
504
505 SetRef(didAlter)
506 if (removed || !exists) SetRef(didChangeSize)
507
508 if (removed && entries.length === 1) {
509 return // undefined
510 }
511
512 if (!exists && !removed && entries.length >= MAX_ARRAY_MAP_SIZE) {
513 return createNodes(ownerID, entries, key, value)
514 }
515
516 const isEditable = ownerID && ownerID === this.ownerID
517 const newEntries = isEditable ? entries : arrCopy(entries)
518
519 if (exists) {
520 if (removed) {
521 if (idx === len - 1) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…