feat: lots more improvements
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
+13
-9
@@ -5,11 +5,12 @@
|
||||
import type { EntityInterface, EntityModelInterface } from "@/types/entity";
|
||||
import type { MessageInterface } from "@/types/message";
|
||||
import { MessageObject } from "./message";
|
||||
import { clonePlain } from './clone-plain';
|
||||
|
||||
export class EntityObject implements EntityModelInterface {
|
||||
|
||||
private _data!: EntityInterface<MessageInterface>;
|
||||
private _properties!: MessageObject;
|
||||
private _properties: MessageObject | undefined = undefined;
|
||||
|
||||
constructor() {
|
||||
this._data = {
|
||||
@@ -27,21 +28,24 @@ export class EntityObject implements EntityModelInterface {
|
||||
}
|
||||
|
||||
fromJson(data: EntityInterface<MessageInterface>): EntityObject {
|
||||
this._data = data;
|
||||
this._data = clonePlain(data);
|
||||
this._properties = undefined;
|
||||
return this;
|
||||
}
|
||||
|
||||
toJson(): EntityInterface<MessageInterface> {
|
||||
return this._data;
|
||||
const json = this._properties
|
||||
? {
|
||||
...this._data,
|
||||
properties: this._properties.toJson(),
|
||||
}
|
||||
: this._data;
|
||||
|
||||
return clonePlain(json);
|
||||
}
|
||||
|
||||
clone(): EntityObject {
|
||||
const cloned = new EntityObject();
|
||||
cloned._data = {
|
||||
...this._data
|
||||
};
|
||||
cloned._properties = this.properties.clone();
|
||||
return cloned;
|
||||
return new EntityObject().fromJson(this.toJson());
|
||||
}
|
||||
|
||||
/** Metadata Properties */
|
||||
|
||||
Reference in New Issue
Block a user