Browse Source

refactor: simplify set logic

feature/data-sources
danstarns 2 years ago
parent
commit
29d2a037bc
  1. 29
      src/data_sources/model/DataRecord.ts

29
src/data_sources/model/DataRecord.ts

@ -139,26 +139,17 @@ export default class DataRecord<T extends DataRecordProps = DataRecordProps> ext
set(attributeName: unknown, value?: unknown, options?: SetOptions): DataRecord { set(attributeName: unknown, value?: unknown, options?: SetOptions): DataRecord {
const onRecordSet = this.dataSource?.transformers?.onRecordSet; const onRecordSet = this.dataSource?.transformers?.onRecordSet;
if (options?.avoidTransformers) { const newValue =
// @ts-ignore options?.avoidTransformers || !onRecordSet
super.set(attributeName, value, options); ? value
return this; : onRecordSet({
} id: this.id,
key: attributeName as string,
value,
});
if (onRecordSet) { super.set(attributeName as string, newValue, options);
const newValue = onRecordSet({
id: this.id,
key: attributeName as string,
value,
});
// @ts-ignore return this;
super.set(attributeName, newValue, options);
return this;
} else {
// @ts-ignore
super.set(attributeName, value, options);
return this;
}
} }
} }

Loading…
Cancel
Save