UNPKG

@tripsnek/tmf

Version:

TypeScript Modeling Framework - A TypeScript port of the Eclipse Modeling Framework (EMF)

47 lines 1.4 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SerializedReference = void 0; class SerializedReference { fromId; toId; refName; constructor(from, to, ref) { this.fromId = from; this.toId = to; this.refName = ref; } static create(fromDId, toDId, fromRef) { return new SerializedReference(fromDId, toDId, fromRef); } /** * Swizzles the object to JSON. */ serialize() { return this.toId; } /** * Restores the swizzled reference. * * @param allObjs * @returns true if the reference was successfully resolved, false if target object not found */ deserialize(allObjs) { //gather the objects and feature const fromObj = allObjs.get(this.fromId); const toObj = allObjs.get(this.toId); if (fromObj && toObj) { const feature = fromObj.eClass().getEStructuralFeature(this.refName); //enforce the reference if (fromObj && toObj && feature) { if (feature.isMany()) fromObj.eGet(feature).add(toObj); else fromObj.eSet(feature, toObj); return true; } } return false; } } exports.SerializedReference = SerializedReference; //# sourceMappingURL=serialized-reference.js.map