mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-23 13:29:02 +08:00
4125038ff8
TODO - [x] basic - [x] storages - [x] producer/consumer - [x] operation pattern - [x] events - [x] worker - [x] readme - [x] peer dependencies
23 lines
544 B
TypeScript
23 lines
544 B
TypeScript
import type { Connection } from './connection';
|
|
|
|
const CONNECTIONS: Map<string, Connection<any>> = new Map();
|
|
export function share<T extends Connection<any>>(conn: T): T {
|
|
if (!conn.shareId) {
|
|
throw new Error(
|
|
`Connection ${conn.constructor.name} is not shareable.\nIf you want to make it shareable, please override [shareId].`
|
|
);
|
|
}
|
|
|
|
const existing = CONNECTIONS.get(conn.shareId);
|
|
|
|
if (existing) {
|
|
existing.ref();
|
|
return existing as T;
|
|
}
|
|
|
|
CONNECTIONS.set(conn.shareId, conn);
|
|
conn.ref();
|
|
|
|
return conn;
|
|
}
|