@assistant-ui/react
Version:
Typescript/React library for AI Chat
66 lines (65 loc) • 2.25 kB
JavaScript
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/api/subscribable/NestedSubscriptionSubject.ts
var NestedSubscriptionSubject_exports = {};
__export(NestedSubscriptionSubject_exports, {
NestedSubscriptionSubject: () => NestedSubscriptionSubject
});
module.exports = __toCommonJS(NestedSubscriptionSubject_exports);
var import_BaseSubject = require("./BaseSubject.js");
var NestedSubscriptionSubject = class extends import_BaseSubject.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?.();
};
}
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
NestedSubscriptionSubject
});
//# sourceMappingURL=NestedSubscriptionSubject.js.map
;