From 017f7356134c306c9ba46b19385c3e96444c613b Mon Sep 17 00:00:00 2001 From: Nikita Dezzpil Orlov Date: Tue, 5 Oct 2021 14:30:18 +0300 Subject: [PATCH] =?UTF-8?q?feat:=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=20=D1=83=D0=BF=D1=80=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20=D1=82=D1=80=D0=B0=D0=BD=D1=81=D1=84=D0=BE=D1=80=D0=BC?= =?UTF-8?q?=D0=B0=D1=86=D0=B8=D0=B5=D0=B9=20=D0=B4=D0=B0=D0=BD=D0=BD=D1=8B?= =?UTF-8?q?=D1=85=20=D0=B4=D0=BB=D1=8F=20=D1=80=D0=B5=D0=BF=D0=BE=D0=B7?= =?UTF-8?q?=D0=B8=D1=82=D0=BE=D1=80=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/repo.ts | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/app/repo.ts b/src/app/repo.ts index a985389..de352e9 100644 --- a/src/app/repo.ts +++ b/src/app/repo.ts @@ -15,6 +15,8 @@ export abstract class Repo> { protected _limit = 0 protected _offset = 0 + private _transformer: (obj: any) => any + /** * Возвращает объект соотв. сущности, например new App() */ @@ -25,21 +27,24 @@ export abstract class Repo> { */ abstract Name(): string - _transformer: (object: any) => any - - constructor(storage: Storage) { + constructor(storage: Storage, transformer?: (obj: any) => any) { this._storage = storage this._entity = this.Entity() - this.resetTransformer() + this.setTransformer(transformer) } - resetTransformer() { - this._transformer = function (object: any): any { - const entity = this.Entity() - entity.data.fromObject(object) - entity._id = object._id - return entity + setTransformer(transformer?: (obj: any) => any): this { + if (transformer) { + this._transformer = transformer + } else { + this._transformer = function (object: any): any { + const entity = this.Entity() + entity.data.fromObject(object) + entity._id = object._id + return entity + } } + return this } get storage(): Storage {