UNPKG

mutation-summary

Version:
94 lines 3.84 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Summary = void 0; /** * Represents a set of changes made to the DOM. */ var Summary = /** @class */ (function () { /** * Creates a new Summary instance given a [[MutationProjection]] and the * [[IQuery]] that was responsible for this summary being generated. * * @param projection The projection containing the changes. * @param query The query that cause the summary to be created. */ function Summary(projection, query) { var _this = this; this.projection = projection; this.added = []; this.removed = []; this.reparented = query.all || query.element || query.characterData ? [] : undefined; this.reordered = query.all ? [] : undefined; projection.getChanged(this, query.elementFilter, query.characterData); if (query.all || query.attribute || query.attributeList) { var filter = query.attribute ? [query.attribute] : query.attributeList; var attributeChanged = projection.attributeChangedNodes(filter); if (query.attribute) { this.valueChanged = attributeChanged[query.attribute] || []; } else { this.attributeChanged = attributeChanged; if (query.attributeList) { query.attributeList.forEach(function (attrName) { if (!_this.attributeChanged.hasOwnProperty(attrName)) _this.attributeChanged[attrName] = []; }); } } } if (query.all || query.characterData) { var characterDataChanged = projection.getCharacterDataChanged(); if (query.characterData) this.valueChanged = characterDataChanged; else this.characterDataChanged = characterDataChanged; } // TODO this seems unnecessary. if (this.reordered) this.getOldPreviousSibling = projection.getOldPreviousSibling.bind(projection); } /** * Will retrieve the previous parentNode for and node. The node must be * contained in the removed element array, otherwise the function throws an * error. * * @param node The node to get the previous parent for. */ Summary.prototype.getOldParentNode = function (node) { return this.projection.getOldParentNode(node); }; /** * Retrieves the previous value of an attribute for an element. The Element * must be contained in the valueChanged element array, otherwise the * function throws an error. * * @param element The element to ge the old value for. * @param name The name off the attribute on the element to get the old value * for. */ Summary.prototype.getOldAttribute = function (element, name) { return this.projection.getOldAttribute(element, name); }; /** * Retrieves the previous text of `node`. `node` must be contained in the * `valueChanged` node array, otherwise the function throws an error. * * @param node The node to get the old character data for. */ Summary.prototype.getOldCharacterData = function (node) { return this.projection.getOldCharacterData(node); }; /** * Retrieves the previous previousSibling for a node. The node must be * contained in the reordered element array, otherwise the function throws * an error. * * @param node The node to get the previous sibling for. */ Summary.prototype.getOldPreviousSibling = function (node) { return this.projection.getOldPreviousSibling(node); }; return Summary; }()); exports.Summary = Summary; //# sourceMappingURL=Summary.js.map