Permalink
Browse files

feat(arraycollection): add each method to loop indexless

  • Loading branch information...
RWOverdijk committed Dec 23, 2016
1 parent cdb1a64 commit 3591fbdc10ed524a0a60220dc14a696e975afcf5
Showing with 19 additions and 1 deletion.
  1. +19 −1 src/ArrayCollection.ts
@@ -20,6 +20,23 @@ export class ArrayCollection<T> extends Array {
return this;
}
/**
* Loop over each item in the collection, without worrying about index changes.
*
* @param {Function} callback
*
* @returns {ArrayCollection}
*/
each(callback: (target: any) => void): ArrayCollection<T> {
let target;
while (target = this.pop()) {
callback(target);
}
return this;
}
/**
* Remove items from the collection when part of the collection.
*
@@ -32,7 +49,8 @@ export class ArrayCollection<T> extends Array {
let itemIndex = this.indexOf(item);
if (itemIndex > -1) {
this.splice(itemIndex, 1);
// Triggers a splice in proxy. Performance win is pretty big.
delete this[itemIndex];
}
});

0 comments on commit 3591fbd

Please sign in to comment.