diff --git a/src/core/AtomList.ts b/src/core/AtomList.ts index 0bc3d752..5acdd20c 100644 --- a/src/core/AtomList.ts +++ b/src/core/AtomList.ts @@ -177,12 +177,13 @@ import { IDisposable } from "./types"; public remove(item: T | ((i: T) => boolean)): boolean { if (item instanceof Function) { - let index: number = 0; let removed: boolean = false; - for (let index = 0; index <= this.length;) { + for (let index = 0; index < this.length;) { const it = this[index]; if (item(it)) { - this.removeAt(index); + this.splice(index, 1); + AtomBinder.invokeItemsEvent(this, "remove", index, it); + AtomBinder.refreshValue(this, "length"); removed = true; continue; } diff --git a/src/tests/core/AtomListTests.ts b/src/tests/core/AtomListTests.ts index f733339b..3c281362 100644 --- a/src/tests/core/AtomListTests.ts +++ b/src/tests/core/AtomListTests.ts @@ -30,6 +30,16 @@ export class AtomListTest extends TestItem { public removeMultiple(): void { const list = [1, 2, 3, 4, 5]; + // remove all even numbers... + list.remove((x) => x <= 2); + + Assert.equals(3, list.length); + } + + @Test + public removeMultipleWithFirst(): void { + const list = [1, 2, 3, 4, 5]; + // remove all even numbers... list.remove((x) => (x % 2) === 0);