ant-design-x-vue-next
Version:
Ant Design X for Vue — community continuation aligned with @ant-design/x
42 lines (41 loc) • 1.99 kB
JavaScript
import { getConversationMessages as a } from "../use-x-chat/conversationStore.mjs";
const n = {
_allConversationStores: /* @__PURE__ */ new Map(),
set(i, e) {
n._allConversationStores.set(i, e);
},
delete(i) {
n._allConversationStores.delete(i);
},
getConversation(i) {
const e = Array.from(n._allConversationStores.values());
for (const r of e) {
const t = r.getConversation(i);
if (t) return t;
}
}
};
class v {
constructor(e, r) {
this.conversations = [], this.listeners = [], this.setActiveConversationKey = (t) => (this.activeConversationKey = t, this.emit(), !0), this.setConversations = (t) => (this.conversations = [...t], this.emit(), !0), this.getConversation = (t) => this.conversations.find((s) => s.key === t), this.addConversation = (t, s) => this.getConversation(t.key) ? !1 : (this.setConversations(
s === "prepend" ? [t, ...this.conversations] : [...this.conversations, t]
), !0), this.setConversation = (t, s) => {
const o = this.getConversation(t);
return o ? (Object.assign(o, s), this.setConversations([...this.conversations]), !0) : !1;
}, this.removeConversation = (t) => {
const s = this.conversations.findIndex((o) => o.key === t);
return s === -1 ? !1 : (this.conversations.splice(s, 1), this.setConversations([...this.conversations]), !0);
}, this.getMessages = (t) => a(t), this.getSnapshot = () => this.conversations, this.getActiveConversationKey = () => this.activeConversationKey, this.subscribe = (t) => (this.listeners.push(t), () => {
this.listeners = this.listeners.filter((s) => s !== t);
}), this.destroy = () => {
n.delete(this.storeKey), this.listeners = [];
}, this.conversations = [...e], this.storeKey = Math.random().toString(36).slice(2), n.set(this.storeKey, this), this.activeConversationKey = r;
}
emit() {
this.listeners.forEach((e) => e());
}
}
export {
v as ConversationStore,
n as conversationStoreHelper
};