feat: lots more improvements
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
@@ -3,11 +3,12 @@
|
||||
*/
|
||||
|
||||
import type { CollectionInterface, CollectionModelInterface, CollectionPropertiesInterface, CollectionPropertiesModelInterface } from "@/types/collection";
|
||||
import { clonePlain } from './clone-plain';
|
||||
|
||||
export class CollectionObject implements CollectionModelInterface {
|
||||
|
||||
_data!: CollectionInterface<CollectionPropertiesInterface>;
|
||||
_properties!: CollectionPropertiesObject;
|
||||
_properties: CollectionPropertiesObject | undefined = undefined;
|
||||
|
||||
constructor() {
|
||||
this._data = {
|
||||
@@ -22,29 +23,24 @@ export class CollectionObject implements CollectionModelInterface {
|
||||
}
|
||||
|
||||
fromJson(data: CollectionInterface): CollectionObject {
|
||||
this._data = data;
|
||||
this._data = clonePlain(data);
|
||||
this._properties = undefined;
|
||||
return this;
|
||||
}
|
||||
|
||||
toJson(): CollectionInterface {
|
||||
const json = {
|
||||
...this._data
|
||||
};
|
||||
if (this._properties) {
|
||||
json.properties = this._properties.toJson();
|
||||
}
|
||||
return json;
|
||||
const json = this._properties
|
||||
? {
|
||||
...this._data,
|
||||
properties: this._properties.toJson(),
|
||||
}
|
||||
: this._data;
|
||||
|
||||
return clonePlain(json);
|
||||
}
|
||||
|
||||
clone(): CollectionObject {
|
||||
const cloned = new CollectionObject();
|
||||
cloned._data = {
|
||||
...this._data,
|
||||
};
|
||||
if (this._properties) {
|
||||
cloned._properties = this._properties.clone();
|
||||
}
|
||||
return cloned;
|
||||
return new CollectionObject().fromJson(this.toJson());
|
||||
}
|
||||
|
||||
/** Immutable Properties */
|
||||
@@ -112,18 +108,16 @@ export class CollectionPropertiesObject implements CollectionPropertiesModelInte
|
||||
}
|
||||
|
||||
fromJson(data: CollectionPropertiesInterface): CollectionPropertiesObject {
|
||||
this._data = data;
|
||||
this._data = clonePlain(data);
|
||||
return this;
|
||||
}
|
||||
|
||||
toJson(): CollectionPropertiesInterface {
|
||||
return this._data;
|
||||
return clonePlain(this._data);
|
||||
}
|
||||
|
||||
clone(): CollectionPropertiesObject {
|
||||
const cloned = new CollectionPropertiesObject();
|
||||
cloned._data = { ...this._data };
|
||||
return cloned;
|
||||
return new CollectionPropertiesObject().fromJson(this.toJson());
|
||||
}
|
||||
|
||||
/** Immutable Properties */
|
||||
|
||||
Reference in New Issue
Block a user