Skip to content
This repository has been archived by the owner on May 8, 2020. It is now read-only.

Commit

Permalink
fix(collection): Fix chrome bug where splice invokes a new collection…
Browse files Browse the repository at this point in the history
… instance
  • Loading branch information
zakhenry committed Jul 18, 2016
1 parent 7459fb5 commit fb5067f
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/common/models/collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}
}

/**
Expand All @@ -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);
}
}

/**
Expand Down

0 comments on commit fb5067f

Please sign in to comment.