MCPcopy Create free account
hub / github.com/activejs/activejs / set

Method set

packages/core/src/lib/list-unit.ts:126–139  ·  view source on GitHub ↗

* Sets the item on the given index in the list-value. \ * Dispatches a new copy of the value, without mutating the current-value. * * It only works if the Unit is not frozen, and the index is valid-numeric. * * @param index The index of the item. \ * A negative index is nor

(index: number, item: Item)

Source from the content-addressed store, hash-verified

124 * @category Custom ListUnit
125 */
126 set(index: number, item: Item): void {
127 if (this.isFrozen || !isValidIndex(index)) {
128 return;
129 }
130 this.checkSerializabilityMaybe(item);
131
132 const listShallowCopy = [...this.rawValue()];
133 listShallowCopy[normalizeIndex(index, this.length)] = this.deepCopyMaybe(item);
134 this.updateValueAndCache(listShallowCopy);
135
136 if (this.eventsSubject?.observers.length && !this.isMuted) {
137 this.eventsSubject.next(new EventListUnitSet(index, item));
138 }
139 }
140
141 /**
142 * Inserts items to the list-{@link value}. \

Callers

nothing calls this directly

Calls 3

isValidIndexFunction · 0.90
normalizeIndexFunction · 0.90
nextMethod · 0.45

Tested by

no test coverage detected