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×   76336× 76336× 2571483× 18830× 18830×     76336× 57506× 57506× 57506× 57506×     18830×   76336×   290749× 290749× 9553713× 76837× 76837×     290749× 213912× 213912× 213912× 213912×     76837×   290749× 290749×   329987× 329987× 270754× 270754× 270754×     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;
});