mframejs
Version:
simple framework
83 lines • 3.42 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
var classPropertyObserver_1 = require("./classPropertyObserver");
var exported_1 = require("../../utils/exported");
var emptyObject = (function () {
function class_1() {
}
return class_1;
}());
var ClassPropertyObserverCreator = (function () {
function ClassPropertyObserverCreator() {
}
ClassPropertyObserverCreator.create = function (_class, observerKey, caller) {
this.classRef = _class && _class.$context;
this.keyParts = exported_1.Cache.keyMaps.getCreate(observerKey);
this.keyNo = 0;
this.keyBlock = this.keyParts[this.keyNo];
ClassPropertyObserverCreator.processKeys(caller);
ClassPropertyObserverCreator.clear();
};
ClassPropertyObserverCreator.remove = function (_class, observerKey, caller) {
this.classRef = _class && _class.$context;
this.keyParts = exported_1.Cache.keyMaps.getCreate(observerKey);
this.keyNo = 0;
this.keyBlock = this.keyParts && this.keyParts[this.keyNo];
ClassPropertyObserverCreator.removeKeys(caller);
ClassPropertyObserverCreator.clear();
};
ClassPropertyObserverCreator.clear = function () {
this.classRef = null;
this.keyParts = null;
this.keyNo = null;
this.keyBlock = null;
};
ClassPropertyObserverCreator.nextKey = function () {
this.keyNo++;
this.keyBlock = this.keyParts[this.keyNo];
};
ClassPropertyObserverCreator.processKeys = function (caller) {
if (!this.classRef.__observer) {
Object.defineProperty(this.classRef, '__observer', {
writable: true,
configurable: true,
value: new emptyObject()
});
}
if (!this.classRef.__observer[this.keyBlock]) {
this.classRef.__observer[this.keyBlock] = new classPropertyObserver_1.ClassPropertyObserver(this.classRef, this.keyBlock);
this.classRef.__observer[this.keyBlock].subscribe(caller);
}
else {
this.classRef.__observer[this.keyBlock].subscribe(caller);
this.classRef.__observer[this.keyBlock].observe();
}
if (this.keyNo !== this.keyParts.length - 1 && this.keyParts.length > 1) {
if (this.classRef) {
this.classRef = this.classRef[this.keyBlock];
}
this.nextKey();
if (this.classRef) {
this.processKeys(caller);
}
}
};
ClassPropertyObserverCreator.removeKeys = function (caller) {
if (this.classRef && this.classRef.__observer) {
if (this.classRef.__observer[this.keyBlock]) {
this.classRef.__observer[this.keyBlock].unsubscribe(caller);
}
}
if (this.keyNo !== this.keyParts.length - 1 && this.keyParts.length > 1) {
if (this.classRef) {
this.classRef = this.classRef[this.keyBlock];
}
this.nextKey();
if (this.classRef) {
this.removeKeys(caller);
}
}
};
return ClassPropertyObserverCreator;
}());
exports.ClassPropertyObserverCreator = ClassPropertyObserverCreator;
//# sourceMappingURL=classPropertyObserverCreator.js.map