UNPKG

@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.

96 lines 3.57 kB
import { ArgumentException } from "../Exception"; import { MODELVERSION } from "../Version"; import { Uuid } from "./Uuid"; import { EventWithSenderArg } from "../EventObject"; import * as Utils from "../Utils/Utils"; import * as _ from "underscore"; var ModelComponent = /** @class */ (function () { function ModelComponent(id, name) { if (name === void 0) { name = ""; } this._name = ""; this._propertyChanged = new EventWithSenderArg(); this.id = (id != null) ? id : new Uuid().toString(); this.name = name; if (this._tags == null) this._tags = {}; } Object.defineProperty(ModelComponent.prototype, "version", { get: function () { return MODELVERSION; }, enumerable: true, configurable: true }); Object.defineProperty(ModelComponent.prototype, "name", { get: function () { return this._name; }, set: function (value) { if (this._name !== value) { this._name = value; this._propertyChanged.notify(this, "name"); } }, enumerable: true, configurable: true }); Object.defineProperty(ModelComponent.prototype, "tags", { get: function () { return this._tags; }, set: function (value) { if (value == null) throw new ArgumentException("value is null!"); this._tags = value; }, enumerable: true, configurable: true }); ModelComponent.prototype._copy = function (source, destination, generateNewIds, appropriateParentContainer) { if (generateNewIds === void 0) { generateNewIds = false; } if (appropriateParentContainer === void 0) { 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] = _.clone(source.tags[i]); } } }; ModelComponent.prototype.getSimplifiedObject = function (omitProperties) { var simplified = Utils.stripForJson(this, omitProperties); simplified["tags"] = this.tags; simplified["id"] = this.id.toString(); return simplified; }; //TODO: modify getSimplifiedObject to accept forServer parameter /*getSimplifiedObjectForServer(omitProperties?: string | string[]) { return this.getSimplifiedObject(omitProperties); }*/ ModelComponent.prototype.generateNewIds = function () { this._generateNewId(); }; ModelComponent.prototype._generateNewId = function () { this.id = new Uuid().toString(); }; ModelComponent.prototype.toString = function () { return this.name; }; ModelComponent.prototype.addPropertyChanged = function (listener) { this._propertyChanged.add(listener); }; ModelComponent.prototype.removePropertyChanged = function (listener) { this._propertyChanged.remove(listener); }; ModelComponent.prototype.equals = function (other) { return this.name === other.name && this.version === other.version; }; return ModelComponent; }()); export { ModelComponent }; //# sourceMappingURL=ModelComponent.js.map