Skip to content

Commit

Permalink
completed model store implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
niksoc-hi committed Feb 10, 2019
1 parent f1f4b79 commit 96a8588
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/ModelStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,23 @@ export class ModelStore<M extends Model> {
private data: M[];

getById(id: number): M {
return this.filter(m => m.id === id)[0];
}

filter(predicate: (obj: M) => boolean): M[] {
return this.data.filter(predicate);
}

add(obj: M): void {
this.data.push(obj);
}

remove(id: number): void {
this.data = this.data.filter(m => m.id !== id);
}

update(obj: M): void {
this.data = this.data.map(m => obj.id === m.id ? obj : m);
}

}

0 comments on commit 96a8588

Please sign in to comment.