{"version":3,"file":"messageSourceKey.mjs","names":[],"sources":["../../../../src/components/MessageList/messageSourceKey.ts"],"sourcesContent":["import type { Channel, Thread } from 'stream-chat';\n\nconst instanceKeys = new WeakMap<object, string>();\nlet nextInstanceKey = 0;\n\n/**\n * String identifying an object instance, usable as a React key. It keys on the instance, not on\n * `cid` or a thread ID, because distinct `Channel` instances can share a `cid` (the client cache\n * is dropped on `disconnectUser`, an app can hold channels from several clients, re-created\n * channels are new objects); an ID key would keep the stale instance's subscriptions and scroll\n * state. The label is for React DevTools, the counter identifies the instance.\n */\nconst getInstanceKey = (instance: object, label: string): string => {\n  const existing = instanceKeys.get(instance);\n  if (existing) return existing;\n\n  nextInstanceKey += 1;\n  const key = `${label}#${nextInstanceKey}`;\n  instanceKeys.set(instance, key);\n\n  return key;\n};\n\n/**\n * Key for the source a message list is bound to. It mirrors `useMessagePaginator()` (the thread's\n * paginator, else the channel's), so the list resets exactly when the paginator it reads from\n * changes, including between two threads of one channel.\n */\nexport const getMessageSourceKey = ({\n  channel,\n  thread,\n}: {\n  channel: Channel;\n  thread?: Thread;\n}): string =>\n  thread\n    ? getInstanceKey(thread, `thread:${thread.id}`)\n    : getInstanceKey(channel, channel.cid);\n"],"mappings":";AAEA,IAAM,+BAAe,IAAI,QAAwB;AACjD,IAAI,kBAAkB;;;;;;;;AAStB,IAAM,kBAAkB,UAAkB,UAA0B;CAClE,MAAM,WAAW,aAAa,IAAI,QAAQ;CAC1C,IAAI,UAAU,OAAO;CAErB,mBAAmB;CACnB,MAAM,MAAM,GAAG,MAAM,GAAG;CACxB,aAAa,IAAI,UAAU,GAAG;CAE9B,OAAO;AACT;;;;;;AAOA,IAAa,uBAAuB,EAClC,SACA,aAKA,SACI,eAAe,QAAQ,UAAU,OAAO,IAAI,IAC5C,eAAe,SAAS,QAAQ,GAAG"}