all files / common/models/highlight/ highlight.js

72.09% Statements 31/43
57.14% Branches 8/14
81.82% Functions 9/11
72.09% Lines 31/43
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  12× 12×   12× 12× 12×   20×   10×                     12×       12×   12×       15×                                    
"use strict";
var immutable_class_1 = require('immutable-class');
var filter_1 = require('../filter/filter');
var check;
var Highlight = (function () {
    function Highlight(parameters) {
        var owner = parameters.owner;
        Iif (typeof owner !== 'string')
            throw new TypeError('owner must be a string');
        this.owner = owner;
        this.delta = parameters.delta;
        this.measure = parameters.measure || null;
    }
    Highlight.isHighlight = function (candidate) {
        return immutable_class_1.isInstanceOf(candidate, Highlight);
    };
    Highlight.fromJS = function (parameters) {
        return new Highlight({
            owner: parameters.owner,
            delta: filter_1.Filter.fromJS(parameters.delta),
            measure: parameters.measure
        });
    };
    Highlight.prototype.valueOf = function () {
        return {
            owner: this.owner,
            delta: this.delta,
            measure: this.measure
        };
    };
    Highlight.prototype.toJS = function () {
        var js = {
            owner: this.owner,
            delta: this.delta.toJS()
        };
        Iif (this.measure)
            js.measure = this.measure;
        return js;
    };
    Highlight.prototype.toJSON = function () {
        return this.toJS();
    };
    Highlight.prototype.toString = function () {
        return "[Highlight " + this.owner + "]";
    };
    Highlight.prototype.equals = function (other) {
        return Highlight.isHighlight(other) &&
            this.owner === other.owner &&
            this.delta.equals(other.delta) &&
            this.measure === other.measure;
    };
    Highlight.prototype.applyToFilter = function (filter) {
        return filter.applyDelta(this.delta);
    };
    Highlight.prototype.constrainToDimensions = function (dimensions, timeAttribute) {
        var delta = this.delta;
        var newDelta = delta.constrainToDimensions(dimensions, timeAttribute);
        if (newDelta === delta)
            return this;
        if (newDelta.length() === 0)
            return null;
        var value = this.valueOf();
        value.delta = newDelta;
        return new Highlight(value);
    };
    return Highlight;
}());
exports.Highlight = Highlight;
check = Highlight;