@convo-lang/convo-lang
Version:
The language of AI
43 lines • 1.07 kB
JavaScript
import { stopWatchingObj, watchObj } from "@iyio/common";
export class ObjectBinding {
constructor({ obj, }) {
this._isDisposed = false;
this.obj = obj;
const watcher = watchObj(obj);
this.disposeListener = watcher.addListenerWithDispose((_, evt) => {
this.sync(evt);
});
}
get isDisposed() { return this._isDisposed; }
dispose() {
if (this._isDisposed) {
return;
}
this._isDisposed = true;
this._dispose();
this.disposeListener();
stopWatchingObj(this.obj);
}
_dispose() {
}
}
export class FnObjectBinding extends ObjectBinding {
constructor(obj, sync) {
super({ obj });
this._sync = sync;
const d = this.deferredEvt;
if (d) {
this.deferredEvt = undefined;
sync(d);
}
}
sync(evt) {
if (this._sync) {
this._sync(evt);
}
else {
this.deferredEvt = evt;
}
}
}
//# sourceMappingURL=ObjectBinding.js.map