@rxap/xml-parser
Version:
Provides a set of decorators and services for parsing and serializing XML documents into TypeScript classes. It simplifies the process of mapping XML elements and attributes to class properties, handling data validation, and serializing objects back into
28 lines • 1.31 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.unlinkFromParent = unlinkFromParent;
const element_child_1 = require("./decorators/element-child");
const element_children_1 = require("./decorators/element-children");
const get_parent_parsers_1 = require("./get-parent-parsers");
function unlinkFromParent(instance) {
var _a;
if (!instance.__parent) {
throw new Error(`The element ${instance.__tag} is not linked to a parent element`);
}
const parent = instance.__parent;
const possibleParentParsers = (0, get_parent_parsers_1.getParentParsers)(instance, parent);
for (const parser of possibleParentParsers) {
if (parser instanceof element_child_1.ElementChildParser) {
if (Reflect.get(parent, parser.propertyKey) === instance) {
Reflect.set(parent, parser.propertyKey, null);
}
}
else if (parser instanceof element_children_1.ElementChildrenParser) {
const array = (_a = Reflect.get(parent, parser.propertyKey)) !== null && _a !== void 0 ? _a : [];
array.splice(array.indexOf(instance), 1);
Reflect.set(parent, parser.propertyKey, array);
}
}
instance.__parent = undefined;
}
//# sourceMappingURL=unlink-from-parent.js.map