From 29d2a037bc7993bd06942f18d71cb52a560ec861 Mon Sep 17 00:00:00 2001 From: danstarns Date: Tue, 27 Aug 2024 20:32:40 -0700 Subject: [PATCH] refactor: simplify set logic --- src/data_sources/model/DataRecord.ts | 29 ++++++++++------------------ 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/src/data_sources/model/DataRecord.ts b/src/data_sources/model/DataRecord.ts index cdb90333d..c2c6772f8 100644 --- a/src/data_sources/model/DataRecord.ts +++ b/src/data_sources/model/DataRecord.ts @@ -139,26 +139,17 @@ export default class DataRecord ext set(attributeName: unknown, value?: unknown, options?: SetOptions): DataRecord { const onRecordSet = this.dataSource?.transformers?.onRecordSet; - if (options?.avoidTransformers) { - // @ts-ignore - super.set(attributeName, value, options); - return this; - } + const newValue = + options?.avoidTransformers || !onRecordSet + ? value + : onRecordSet({ + id: this.id, + key: attributeName as string, + value, + }); - if (onRecordSet) { - const newValue = onRecordSet({ - id: this.id, - key: attributeName as string, - value, - }); + super.set(attributeName as string, newValue, options); - // @ts-ignore - super.set(attributeName, newValue, options); - return this; - } else { - // @ts-ignore - super.set(attributeName, value, options); - return this; - } + return this; } }