UNPKG

mframejs

Version:
75 lines 2.85 kB
import { ClassPropertyObserver } from './classPropertyObserver'; import { Cache } from '../../utils/exported'; const emptyObject = class { }; export class ClassPropertyObserverCreator { static create(_class, observerKey, caller) { this.classRef = _class && _class.$context; this.keyParts = Cache.keyMaps.getCreate(observerKey); this.keyNo = 0; this.keyBlock = this.keyParts[this.keyNo]; ClassPropertyObserverCreator.processKeys(caller); ClassPropertyObserverCreator.clear(); } static remove(_class, observerKey, caller) { this.classRef = _class && _class.$context; this.keyParts = Cache.keyMaps.getCreate(observerKey); this.keyNo = 0; this.keyBlock = this.keyParts && this.keyParts[this.keyNo]; ClassPropertyObserverCreator.removeKeys(caller); ClassPropertyObserverCreator.clear(); } static clear() { this.classRef = null; this.keyParts = null; this.keyNo = null; this.keyBlock = null; } static nextKey() { this.keyNo++; this.keyBlock = this.keyParts[this.keyNo]; } static processKeys(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(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); } } } static removeKeys(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); } } } } //# sourceMappingURL=classPropertyObserverCreator.js.map