all files / document-editor/base/ unique-formats.js

95.83% Statements 46/48
91.67% Branches 11/12
100% Functions 8/8
95.83% Lines 46/48
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71   12×   81540× 81540× 2979086× 20115× 20115×     81540× 61425× 61425× 61425× 61425×     20115×   81540×   302578× 302578× 10810538× 81272× 81272×     302578× 221306× 221306× 221306× 221306×     81272×   302578× 302578×   346306× 346306× 282031× 282031× 282031×     111×         111×          
define(["require", "exports", "@syncfusion/ej2-base", "./unique-format"], function (require, exports, ej2_base_1, unique_format_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var WUniqueFormats = (function () {
        function WUniqueFormats() {
            this.items = [];
        }
        WUniqueFormats.prototype.addUniqueFormat = function (format, type) {
            var matchedFormat = undefined;
            for (var i = 0; i < this.items.length; i++) {
                if (this.items[i].isEqual(format, undefined, undefined)) {
                    matchedFormat = this.items[i];
                    break;
                }
            }
            if (ej2_base_1.isNullOrUndefined(matchedFormat)) {
                matchedFormat = new unique_format_1.WUniqueFormat(type);
                matchedFormat.propertiesHash = format;
                matchedFormat.referenceCount = 1;
                this.items.push(matchedFormat);
            }
            else {
                matchedFormat.referenceCount++;
            }
            return matchedFormat;
        };
        WUniqueFormats.prototype.updateUniqueFormat = function (uniqueFormat, property, value) {
            var matchedFormat = undefined;
            for (var i = 0; i < this.items.length; i++) {
                if (this.items[i].isEqual(uniqueFormat.propertiesHash, property, value)) {
                    matchedFormat = this.items[i];
                    break;
                }
            }
            if (ej2_base_1.isNullOrUndefined(matchedFormat)) {
                matchedFormat = new unique_format_1.WUniqueFormat(uniqueFormat.uniqueFormatType);
                matchedFormat.cloneItems(uniqueFormat, property, value, uniqueFormat.uniqueFormatType);
                matchedFormat.referenceCount = 1;
                this.items.push(matchedFormat);
            }
            else {
                matchedFormat.referenceCount++;
            }
            this.remove(uniqueFormat);
            return matchedFormat;
        };
        WUniqueFormats.prototype.remove = function (uniqueFormat) {
            uniqueFormat.referenceCount--;
            if (uniqueFormat.referenceCount <= 0) {
                this.items.splice(this.items.indexOf(uniqueFormat), 1);
                uniqueFormat.destroy();
                uniqueFormat = undefined;
            }
        };
        WUniqueFormats.prototype.clear = function () {
            Iif (ej2_base_1.isNullOrUndefined(this.items)) {
                for (var i = 0; i < this.items.length; i++) {
                    this.items[i].destroy();
                }
            }
            this.items = [];
        };
        WUniqueFormats.prototype.destroy = function () {
            this.clear();
            this.items = undefined;
        };
        return WUniqueFormats;
    }());
    exports.WUniqueFormats = WUniqueFormats;
});