mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-02 01:49:51 +08:00
feat(nbstore): init (#7639)
TODO - [x] basic - [x] storages - [x] producer/consumer - [x] operation pattern - [x] events - [x] worker - [x] readme - [x] peer dependencies
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
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;
|
||||
}
|
||||
Reference in New Issue
Block a user