all files / built/src/ Polymorph.js

100% Statements 37/37
90.63% Branches 29/32
100% Functions 9/9
100% Lines 34/34
1 statement, 6 branches Ignored     
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                                                                 
"use strict";
/* istanbul ignore next */
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    Iif (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) Eif (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var mobx_1 = require("mobx");
var json_1 = require("./json");
var Polymorph = (function () {
    function Polymorph(type, factory) {
        this.factory = factory;
        this.type = type;
        this.ref = factory(type);
    }
    Polymorph.prototype.dispose = function () {
        Eif (this.ref && this.ref.dispose) {
            this.ref.dispose();
        }
    };
    Object.defineProperty(Polymorph.prototype, "target", {
        get: function () {
            return this.ref;
        },
        enumerable: true,
        configurable: true
    });
    Polymorph.prototype.get = function () {
        return this.type;
    };
    Polymorph.prototype.set = function (type) {
        Eif (this.type !== type) {
            this.type = type;
            this.dispose();
            this.ref = this.factory(this.type);
        }
    };
    Object.defineProperty(Polymorph.prototype, "json", {
        get: function () {
            return {
                type: this.type,
                settings: json_1.json.save(this.ref)
            };
        },
        set: function (data) {
            Eif (data && data.type) {
                this.set(data.type);
                json_1.json.load(this.ref, data.settings);
            }
        },
        enumerable: true,
        configurable: true
    });
    return Polymorph;
}());
__decorate([
    mobx_1.observable
], Polymorph.prototype, "type", void 0);
__decorate([
    mobx_1.observable.ref
], Polymorph.prototype, "ref", void 0);
__decorate([
    mobx_1.computed
], Polymorph.prototype, "json", null);
exports.Polymorph = Polymorph;
//# sourceMappingURL=Polymorph.js.map