MCPcopy
hub / github.com/immutable-js/immutable-js / update

Method update

src/Map.js:357–404  ·  view source on GitHub ↗
(ownerID, shift, keyHash, key, value, didChangeSize, didAlter)

Source from the content-addressed store, hash-verified

355 }
356
357 update(ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
358 if (keyHash === undefined) {
359 keyHash = hash(key);
360 }
361 const idx = (shift === 0 ? keyHash : keyHash >>> shift) & MASK;
362 const removed = value === NOT_SET;
363 const nodes = this.nodes;
364 const node = nodes[idx];
365
366 if (removed && !node) {
367 return this;
368 }
369
370 const newNode = updateNode(
371 node,
372 ownerID,
373 shift + SHIFT,
374 keyHash,
375 key,
376 value,
377 didChangeSize,
378 didAlter
379 );
380 if (newNode === node) {
381 return this;
382 }
383
384 let newCount = this.count;
385 if (!node) {
386 newCount++;
387 } else if (!newNode) {
388 newCount--;
389 if (newCount < MIN_HASH_ARRAY_MAP_SIZE) {
390 return packNodes(ownerID, nodes, newCount, idx);
391 }
392 }
393
394 const isEditable = ownerID && ownerID === this.ownerID;
395 const newNodes = setAt(nodes, idx, newNode, isEditable);
396
397 if (isEditable) {
398 this.count = newCount;
399 this.nodes = newNodes;
400 return this;
401 }
402
403 return new HashArrayMapNode(ownerID, newCount, newNodes);
404 }
405}
406
407/**

Callers

nothing calls this directly

Calls 4

hashFunction · 0.90
updateNodeFunction · 0.85
packNodesFunction · 0.85
setAtFunction · 0.85

Tested by

no test coverage detected