mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-12 12:28:42 +00:00
33 lines
960 B
TypeScript
33 lines
960 B
TypeScript
import '@affine/core/bootstrap/browser';
|
|
|
|
import { broadcastChannelStorages } from '@affine/nbstore/broadcast-channel';
|
|
import { cloudStorages } from '@affine/nbstore/cloud';
|
|
import { idbStorages } from '@affine/nbstore/idb';
|
|
import { idbV1Storages } from '@affine/nbstore/idb/v1';
|
|
import {
|
|
StoreManagerConsumer,
|
|
type WorkerManagerOps,
|
|
} from '@affine/nbstore/worker/consumer';
|
|
import { type MessageCommunicapable, OpConsumer } from '@toeverything/infra/op';
|
|
|
|
const consumer = new StoreManagerConsumer([
|
|
...idbStorages,
|
|
...idbV1Storages,
|
|
...broadcastChannelStorages,
|
|
...cloudStorages,
|
|
]);
|
|
|
|
if ('onconnect' in globalThis) {
|
|
// if in shared worker
|
|
|
|
(globalThis as any).onconnect = (event: MessageEvent) => {
|
|
const port = event.ports[0];
|
|
consumer.bindConsumer(new OpConsumer<WorkerManagerOps>(port));
|
|
};
|
|
} else {
|
|
// if in worker
|
|
consumer.bindConsumer(
|
|
new OpConsumer<WorkerManagerOps>(globalThis as MessageCommunicapable)
|
|
);
|
|
}
|