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

Function updateList

src/List.js:459–505  ·  view source on GitHub ↗
(list, index, value)

Source from the content-addressed store, hash-verified

457}
458
459function updateList(list, index, value) {
460 index = wrapIndex(list, index);
461
462 if (index !== index) {
463 return list;
464 }
465
466 if (index >= list.size || index < 0) {
467 return list.withMutations((list) => {
468 // eslint-disable-next-line @typescript-eslint/no-unused-expressions -- TODO enable eslint here
469 index < 0
470 ? setListBounds(list, index).set(0, value)
471 : setListBounds(list, 0, index + 1).set(index, value);
472 });
473 }
474
475 index += list._origin;
476
477 let newTail = list._tail;
478 let newRoot = list._root;
479 const didAlter = MakeRef();
480 if (index >= getTailOffset(list._capacity)) {
481 newTail = updateVNode(newTail, list.__ownerID, 0, index, value, didAlter);
482 } else {
483 newRoot = updateVNode(
484 newRoot,
485 list.__ownerID,
486 list._level,
487 index,
488 value,
489 didAlter
490 );
491 }
492
493 if (!didAlter.value) {
494 return list;
495 }
496
497 if (list.__ownerID) {
498 list._root = newRoot;
499 list._tail = newTail;
500 list.__hash = undefined;
501 list.__altered = true;
502 return list;
503 }
504 return makeList(list._origin, list._capacity, list._level, newRoot, newTail);
505}
506
507function updateVNode(node, ownerID, level, index, value, didAlter) {
508 const idx = (index >>> level) & MASK;

Callers 1

setMethod · 0.85

Calls 8

wrapIndexFunction · 0.90
MakeRefFunction · 0.90
setListBoundsFunction · 0.85
getTailOffsetFunction · 0.85
updateVNodeFunction · 0.85
makeListFunction · 0.85
withMutationsMethod · 0.65
setMethod · 0.65

Tested by

no test coverage detected