mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-18 18:46:19 +08:00
feat(editor): replace slot with rxjs subject (#10768)
This commit is contained in:
@@ -11,11 +11,11 @@ export function useAllBlockSuiteDocMeta(docCollection: Workspace): DocMeta[] {
|
||||
weakMap.set(docCollection, baseAtom);
|
||||
baseAtom.onMount = set => {
|
||||
set([...docCollection.meta.docMetas]);
|
||||
const dispose = docCollection.slots.docListUpdated.on(() => {
|
||||
const dispose = docCollection.slots.docListUpdated.subscribe(() => {
|
||||
set([...docCollection.meta.docMetas]);
|
||||
});
|
||||
return () => {
|
||||
dispose.dispose();
|
||||
dispose.unsubscribe();
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { DebugLogger } from '@affine/debug';
|
||||
import { DisposableGroup } from '@blocksuite/affine/global/slot';
|
||||
import { DisposableGroup } from '@blocksuite/affine/global/disposable';
|
||||
import type { Store, Workspace } from '@blocksuite/affine/store';
|
||||
import { useEffect, useState } from 'react';
|
||||
|
||||
@@ -16,14 +16,14 @@ export function useDocCollectionPage(
|
||||
useEffect(() => {
|
||||
const group = new DisposableGroup();
|
||||
group.add(
|
||||
docCollection.slots.docCreated.on(id => {
|
||||
docCollection.slots.docCreated.subscribe(id => {
|
||||
if (pageId === id) {
|
||||
setPage(docCollection.getDoc(id));
|
||||
}
|
||||
})
|
||||
);
|
||||
group.add(
|
||||
docCollection.slots.docRemoved.on(id => {
|
||||
docCollection.slots.docRemoved.subscribe(id => {
|
||||
if (pageId === id) {
|
||||
setPage(null);
|
||||
}
|
||||
|
||||
@@ -69,16 +69,16 @@ export function useBlockSuitePagePreview(page: Store | null): Atom<string> {
|
||||
const baseAtom = atom<string>('');
|
||||
baseAtom.onMount = set => {
|
||||
const disposables = [
|
||||
page.slots.ready.on(() => {
|
||||
page.slots.ready.subscribe(() => {
|
||||
set(getPagePreviewText(page));
|
||||
}),
|
||||
page.slots.blockUpdated.on(() => {
|
||||
page.slots.blockUpdated.subscribe(() => {
|
||||
set(getPagePreviewText(page));
|
||||
}),
|
||||
];
|
||||
set(getPagePreviewText(page));
|
||||
return () => {
|
||||
disposables.forEach(disposable => disposable.dispose());
|
||||
disposables.forEach(disposable => disposable.unsubscribe());
|
||||
};
|
||||
};
|
||||
weakMap.set(page, baseAtom);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { DebugLogger } from '@affine/debug';
|
||||
import { DisposableGroup } from '@blocksuite/affine/global/slot';
|
||||
import { DisposableGroup } from '@blocksuite/affine/global/disposable';
|
||||
import type { Store, Workspace } from '@blocksuite/affine/store';
|
||||
import { useEffect, useState } from 'react';
|
||||
|
||||
@@ -16,14 +16,14 @@ export function useDocCollectionPage(
|
||||
useEffect(() => {
|
||||
const group = new DisposableGroup();
|
||||
group.add(
|
||||
docCollection.slots.docCreated.on(id => {
|
||||
docCollection.slots.docCreated.subscribe(id => {
|
||||
if (pageId === id) {
|
||||
setPage(docCollection.getDoc(id));
|
||||
}
|
||||
})
|
||||
);
|
||||
group.add(
|
||||
docCollection.slots.docRemoved.on(id => {
|
||||
docCollection.slots.docRemoved.subscribe(id => {
|
||||
if (pageId === id) {
|
||||
setPage(null);
|
||||
}
|
||||
|
||||
@@ -111,14 +111,14 @@ export const WorkspaceSideEffects = () => {
|
||||
})
|
||||
);
|
||||
|
||||
const disposable = AIProvider.slots.requestInsertTemplate.on(
|
||||
const disposable = AIProvider.slots.requestInsertTemplate.subscribe(
|
||||
({ template, mode }) => {
|
||||
insertTemplate({ template, mode });
|
||||
}
|
||||
);
|
||||
|
||||
return () => {
|
||||
disposable.dispose();
|
||||
disposable.unsubscribe();
|
||||
insertTemplate.unsubscribe();
|
||||
};
|
||||
}, [
|
||||
@@ -134,14 +134,14 @@ export const WorkspaceSideEffects = () => {
|
||||
const globalDialogService = useService(GlobalDialogService);
|
||||
|
||||
useEffect(() => {
|
||||
const disposable = AIProvider.slots.requestUpgradePlan.on(() => {
|
||||
const disposable = AIProvider.slots.requestUpgradePlan.subscribe(() => {
|
||||
workspaceDialogService.open('setting', {
|
||||
activeTab: 'billing',
|
||||
});
|
||||
track.$.paywall.aiAction.viewPlans();
|
||||
});
|
||||
return () => {
|
||||
disposable.dispose();
|
||||
disposable.unsubscribe();
|
||||
};
|
||||
}, [workspaceDialogService]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user