mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-14 21:27:20 +00:00
feat(nbstore): share worker between workspaces (#9947)
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
// ORDER MATTERS
|
||||
import './env';
|
||||
import './public-path';
|
||||
import './shared-worker';
|
||||
import './polyfill/browser';
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
// ORDER MATTERS
|
||||
import './env';
|
||||
import './public-path';
|
||||
import './shared-worker';
|
||||
import './polyfill/electron';
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
/**
|
||||
* This is a wrapper for SharedWorker,
|
||||
* added the `name` parameter to the `SharedWorker` URL so that
|
||||
* multiple `SharedWorkers` can share one script file.
|
||||
*/
|
||||
const rawSharedWorker = globalThis.SharedWorker;
|
||||
|
||||
// TODO(@eyhn): remove this when we can use single shared worker for all workspaces
|
||||
function PatchedSharedWorker(
|
||||
urlParam: URL | string,
|
||||
options?: string | { name: string }
|
||||
) {
|
||||
const url = typeof urlParam === 'string' ? new URL(urlParam) : urlParam;
|
||||
if (options) {
|
||||
url.searchParams.append(
|
||||
typeof options === 'string' ? options : options.name,
|
||||
''
|
||||
);
|
||||
}
|
||||
return new rawSharedWorker(url, options);
|
||||
}
|
||||
// if SharedWorker is not supported, do nothing
|
||||
if (rawSharedWorker) {
|
||||
globalThis.SharedWorker = PatchedSharedWorker as any;
|
||||
}
|
||||
Reference in New Issue
Block a user