From 96a85887b85a9353294cc528a6000664a9b4c7f0 Mon Sep 17 00:00:00 2001 From: Nikhil Satish Date: Sun, 10 Feb 2019 18:41:11 +0530 Subject: [PATCH] completed model store implementation --- src/ModelStore.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/ModelStore.ts b/src/ModelStore.ts index 57767af..b821660 100644 --- a/src/ModelStore.ts +++ b/src/ModelStore.ts @@ -2,18 +2,23 @@ export class ModelStore { 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); } }