mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-14 21:27:20 +00:00
refactor: webpack config (#11421)
This commit is contained in:
32
packages/frontend/apps/mobile/src/nbstore.worker.ts
Normal file
32
packages/frontend/apps/mobile/src/nbstore.worker.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
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)
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user