@assistant-ui/react
Version:
React components for AI chat.
41 lines • 1.13 kB
JavaScript
// src/api/subscribable/NestedSubscriptionSubject.ts
import { BaseSubject } from "./BaseSubject.mjs";
var NestedSubscriptionSubject = class extends BaseSubject {
constructor(binding) {
super();
this.binding = binding;
}
get path() {
return this.binding.path;
}
getState() {
return this.binding.getState();
}
outerSubscribe(callback) {
return this.binding.subscribe(callback);
}
_connect() {
const callback = () => {
this.notifySubscribers();
};
let lastState = this.binding.getState();
let innerUnsubscribe = lastState?.subscribe(callback);
const onRuntimeUpdate = () => {
const newState = this.binding.getState();
if (newState === lastState) return;
lastState = newState;
innerUnsubscribe?.();
innerUnsubscribe = this.binding.getState()?.subscribe(callback);
callback();
};
const outerUnsubscribe = this.outerSubscribe(onRuntimeUpdate);
return () => {
outerUnsubscribe?.();
innerUnsubscribe?.();
};
}
};
export {
NestedSubscriptionSubject
};
//# sourceMappingURL=NestedSubscriptionSubject.mjs.map