mirror of
https://github.com/toeverything/AFFiNE.git
synced 2024-12-25 10:03:45 +03:00
fix: providers get disconnected after opening the setting and close it (#4429)
Co-authored-by: Alex Yang <himself65@outlook.com>
This commit is contained in:
parent
1ddae40fb2
commit
d5f4fbcdb5
@ -18,10 +18,12 @@ const workspaceActiveAtomWeakMap = new WeakMap<
|
|||||||
const workspaceActiveWeakMap = new WeakMap<Workspace, boolean>();
|
const workspaceActiveWeakMap = new WeakMap<Workspace, boolean>();
|
||||||
|
|
||||||
// Whether the workspace has been enabled the passive effect (background)
|
// Whether the workspace has been enabled the passive effect (background)
|
||||||
const workspacePassiveEffectWeakMap = new WeakMap<Workspace, boolean>();
|
const workspacePassiveEffectWeakMap = new WeakMap<Workspace, number>();
|
||||||
|
|
||||||
export function enablePassiveProviders(workspace: Workspace) {
|
export function enablePassiveProviders(workspace: Workspace) {
|
||||||
if (workspacePassiveEffectWeakMap.get(workspace) === true) {
|
const value = workspacePassiveEffectWeakMap.get(workspace);
|
||||||
|
if (value !== undefined && value !== 0) {
|
||||||
|
workspacePassiveEffectWeakMap.set(workspace, value + 1);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const providers = workspace.providers.filter(
|
const providers = workspace.providers.filter(
|
||||||
@ -31,13 +33,14 @@ export function enablePassiveProviders(workspace: Workspace) {
|
|||||||
providers.forEach(provider => {
|
providers.forEach(provider => {
|
||||||
provider.connect();
|
provider.connect();
|
||||||
});
|
});
|
||||||
workspacePassiveEffectWeakMap.set(workspace, true);
|
workspacePassiveEffectWeakMap.set(workspace, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function disablePassiveProviders(workspace: Workspace) {
|
export function disablePassiveProviders(workspace: Workspace) {
|
||||||
if (workspacePassiveEffectWeakMap.get(workspace) !== true) {
|
const value = workspacePassiveEffectWeakMap.get(workspace);
|
||||||
return;
|
if (value && value > 0) {
|
||||||
}
|
workspacePassiveEffectWeakMap.set(workspace, value - 1);
|
||||||
|
if (value - 1 === 0) {
|
||||||
const providers = workspace.providers.filter(
|
const providers = workspace.providers.filter(
|
||||||
(provider): provider is PassiveDocProvider =>
|
(provider): provider is PassiveDocProvider =>
|
||||||
'passive' in provider && provider.passive === true
|
'passive' in provider && provider.passive === true
|
||||||
@ -46,6 +49,9 @@ export function disablePassiveProviders(workspace: Workspace) {
|
|||||||
provider.disconnect();
|
provider.disconnect();
|
||||||
});
|
});
|
||||||
workspacePassiveEffectWeakMap.delete(workspace);
|
workspacePassiveEffectWeakMap.delete(workspace);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function waitForWorkspace(workspace: Workspace) {
|
export async function waitForWorkspace(workspace: Workspace) {
|
||||||
|
Loading…
Reference in New Issue
Block a user