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

Method delete

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

* Deletes items at given indices in the list-value. \ * Dispatches a new copy of the value, without mutating the current-value. \ * It doesn't modify the length of the list as these indices are only deleted, not removed. * * It only works if the Unit is not frozen, and * the l

(...indices: number[])

Source from the content-addressed store, hash-verified

266 * @category Custom ListUnit
267 */
268 delete(...indices: number[]): Item[] {
269 indices = sanitizeIndices(indices, this.length).filter(i => this.hasOwnProperty(i));
270
271 if (this.isFrozen || indices.length === 0 || this.isEmpty) {
272 return [];
273 }
274
275 const deletedItems = [];
276 const listShallowCopy = [...this.rawValue()];
277 indices.forEach(index => {
278 deletedItems.push(this.deepCopyMaybe(listShallowCopy[index]));
279 delete listShallowCopy[index];
280 });
281 this.updateValueAndCache(listShallowCopy);
282
283 if (this.eventsSubject?.observers.length && !this.isMuted) {
284 this.eventsSubject.next(new EventListUnitDelete(indices, deletedItems));
285 }
286 return deletedItems;
287 }
288
289 /**
290 * Deletes items from the list-{@link value} where the predicate returns `true`. \

Callers 1

deleteIfMethod · 0.95

Calls 3

sanitizeIndicesFunction · 0.90
pushMethod · 0.80
nextMethod · 0.45

Tested by

no test coverage detected