UNPKG

mframejs

Version:
75 lines 2.83 kB
import { ClassArrayObserver } from './classArrayObserver'; import { Cache } from '../../utils/exported'; const emptyObject = class { }; export class ClassArrayObserverCreator { 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]; ClassArrayObserverCreator.processKeys(caller); ClassArrayObserverCreator.clear(); } static remove(_class, observerKey, caller) { this.classRef = _class.$context; this.keyParts = Cache.keyMaps.getCreate(observerKey); this.keyNo = 0; this.keyBlock = this.keyParts[this.keyNo]; ClassArrayObserverCreator.removeKeys(caller); ClassArrayObserverCreator.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.__observerArray) { Object.defineProperty(this.classRef, '__observerArray', { writable: true, configurable: true, value: new emptyObject() }); } if (!this.classRef.__observerArray[this.keyBlock]) { this.classRef.__observerArray[this.keyBlock] = new ClassArrayObserver(this.classRef, this.keyBlock); this.classRef.__observerArray[this.keyBlock].subscribe(caller); } else { this.classRef.__observerArray[this.keyBlock].subscribe(caller); this.classRef.__observerArray[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.__observerArray) { if (this.classRef.__observerArray[this.keyBlock]) { this.classRef.__observerArray[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=classArrayObserverCreator.js.map