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

Method remove

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

* Removes items at given indices from the list-value. \ * Dispatches a new copy of the value, without mutating the current-value. \ * It modifies the length of the list as these indices are not deleted, * rather removed using `Array.prototype.splice`. * * It only works if the

(...indices: number[])

Source from the content-addressed store, hash-verified

193 * @category Custom ListUnit
194 */
195 remove(...indices: number[]): Item[] {
196 const listLength = this.length;
197 indices = sanitizeIndices(indices, listLength).filter(i => this.hasOwnProperty(i));
198
199 if (this.isFrozen || !indices.length || this.isEmpty) {
200 return [];
201 }
202
203 indices.sort().reverse();
204 const removedItems = [];
205 const listShallowCopy = [...this.rawValue()];
206
207 indices.forEach(index => {
208 removedItems.push(...this.deepCopyMaybe(listShallowCopy.splice(index, 1)));
209 });
210 this.updateValueAndCache(listShallowCopy);
211 removedItems.reverse();
212
213 if (this.eventsSubject?.observers.length && !this.isMuted) {
214 this.eventsSubject.next(new EventListUnitRemove(indices, removedItems));
215 }
216 return removedItems;
217 }
218
219 /**
220 * Removes items from the list-{@link value} where the predicate returns `truthy` value. \

Callers 3

removeIfMethod · 0.95
utils.tsFile · 0.45
list-unit.spec.tsFile · 0.45

Calls 6

sanitizeIndicesFunction · 0.90
reverseMethod · 0.80
sortMethod · 0.80
pushMethod · 0.80
spliceMethod · 0.80
nextMethod · 0.45

Tested by

no test coverage detected