@aurigma/design-atoms-model
Version:
Design Atoms is a part of Customer's Canvas SDK which allows for manipulating individual design elements through your code.
74 lines • 2.26 kB
JavaScript
import { ArgumentException } from "../Exception";
import { MODELVERSION } from "../Version";
import { Uuid } from "./Uuid";
import { EventWithSenderArg } from "../EventObject";
import * as Utils from "../Utils/Utils";
export class ModelComponent {
get version() {
return MODELVERSION;
}
constructor(id, name = "") {
this._name = "";
this._propertyChanged = new EventWithSenderArg();
this.id = (id != null) ? id : new Uuid().toString();
this.name = name;
if (this._tags == null)
this._tags = {};
}
get name() {
return this._name;
}
set name(value) {
if (this._name !== value) {
this._name = value;
this._propertyChanged.notify(this, "name");
}
}
get tags() {
return this._tags;
}
set tags(value) {
if (value == null)
throw new ArgumentException("value is null!");
this._tags = value;
}
_copy(source, destination, generateNewIds = false, appropriateParentContainer = false) {
destination.name = source.name;
if (generateNewIds)
destination.generateNewIds();
else
destination.id = source.id;
if (source.tags != null) {
destination.tags = {};
for (var i in source.tags) {
destination.tags[i] = structuredClone(source.tags[i]);
}
}
}
getSimplifiedObject(omitProperties) {
const simplified = Utils.stripForJson(this, omitProperties);
simplified["tags"] = this.tags;
simplified["id"] = this.id.toString();
return simplified;
}
generateNewIds() {
this._generateNewId();
}
_generateNewId() {
this.id = new Uuid().toString();
}
toString() {
return this.name;
}
addPropertyChanged(listener) {
this._propertyChanged.add(listener);
}
removePropertyChanged(listener) {
this._propertyChanged.remove(listener);
}
equals(other) {
return this.name === other.name &&
this.version === other.version;
}
}
//# sourceMappingURL=ModelComponent.js.map