"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 |