Permalink
Browse files

fix(collection): Fix chrome bug where splice invokes a new collection…

… instance
  • Loading branch information...
zakhenry committed Jul 18, 2016
1 parent 7459fb5 commit fb5067f5d3d4184938859b73ea06fc3a60ef7fd4
Showing with 9 additions and 4 deletions.
  1. +9 −4 src/common/models/collection.ts
@@ -3,7 +3,6 @@
*/
/** End Typedoc Module Declaration */
import { AbstractModel, identifier } from './model';
import * as _ from 'lodash';
/**
* Collection holds an array of [[AbstractModel|models]]. It provides common collection manipulation
* methods for the controllers, services etc to work with models in an abstracted manner
@@ -12,7 +11,10 @@ export class Collection<T extends AbstractModel> extends Array<T> {
constructor(initialItems?: T[]) {
super();
this.push.apply(this, initialItems);
if (initialItems.length){
this.push.apply(this, initialItems);
}
}
/**
@@ -35,8 +37,11 @@ export class Collection<T extends AbstractModel> extends Array<T> {
* Remove an item from the collection
* @param model
*/
public remove(model:T):void {
_.pull(this, model);
public remove(model: T): void {
const index: number = this.findIndex((item: T) => item.getIdentifier() === model.getIdentifier());
if (index >= 0) {
this.splice(index, 1);
}
}
/**

0 comments on commit fb5067f

Please sign in to comment.