Skip to content

There can be more than Notion and Miro. AFFiNE(pronounced [ə‘fain]) is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.

refactor(editor): merge docCreated and docAdded slot (#9489)

Saul-Mirone53f7480cb87b
diff --git a/blocksuite/affine/block-data-view/src/data-source.ts b/blocksuite/affine/block-data-view/src/data-source.ts
index 941069d9fc..b224143b56 100644
--- a/blocksuite/affine/block-data-view/src/data-source.ts
+++ b/blocksuite/affine/block-data-view/src/data-source.ts
@@ -82,7 +82,7 @@ export class BlockQueryDataSource extends DataSourceBase {
this.workspace.docs.forEach(doc => {
this.listenToDoc(doc.getDoc());
});
- this.workspace.slots.docAdded.on(id => {
+ this.workspace.slots.docCreated.on(id => {
const doc = this.workspace.getDoc(id);
if (doc) {
this.listenToDoc(doc);
diff --git a/blocksuite/framework/store/src/store/collection.ts b/blocksuite/framework/store/src/store/collection.ts
index 68c60131e7..e412a0dca4 100644
--- a/blocksuite/framework/store/src/store/collection.ts
+++ b/blocksuite/framework/store/src/store/collection.ts
@@ -94,7 +94,6 @@ export class DocCollection {
meta: DocCollectionMeta;
slots = {
- docAdded: new Slot<string>(),
docUpdated: new Slot(),
docRemoved: new Slot<string>(),
docCreated: new Slot<string>(),
@@ -163,7 +162,6 @@ export class DocCollection {
idGenerator: this.idGenerator,
});
this.blockCollections.set(doc.id, doc);
- this.slots.docAdded.emit(doc.id);
});
this.meta.docMetaUpdated.on(() => this.slots.docUpdated.emit());
diff --git a/blocksuite/playground/apps/starter/utils/collection.ts b/blocksuite/playground/apps/starter/utils/collection.ts
index d6769e4c4d..5d801622b4 100644
--- a/blocksuite/playground/apps/starter/utils/collection.ts
+++ b/blocksuite/playground/apps/starter/utils/collection.ts
@@ -107,7 +107,7 @@ export async function initStarterDocCollection(collection: DocCollection) {
let firstDoc = firstCollection?.getDoc();
if (!firstDoc) {
await new Promise<string>(resolve =>
- collection.slots.docAdded.once(resolve)
+ collection.slots.docCreated.once(resolve)
);
const firstCollection = collection.docs.values().next().value as
| BlockCollection
diff --git a/blocksuite/tests-legacy/utils/actions/misc.ts b/blocksuite/tests-legacy/utils/actions/misc.ts
index 1ac879beff..3774b221a6 100644
--- a/blocksuite/tests-legacy/utils/actions/misc.ts
+++ b/blocksuite/tests-legacy/utils/actions/misc.ts
@@ -201,7 +201,7 @@ async function initEmptyEditor({
window.doc = firstDoc;
waitForMountPageEditor(firstDoc).catch;
} else {
- collection.slots.docAdded.on(docId => {
+ collection.slots.docCreated.on(docId => {
const doc = collection.getDoc(docId);
if (!doc) {
throw new Error(`Failed to get doc ${docId}`);
diff --git a/packages/frontend/core/src/components/hooks/use-block-suite-workspace-page.ts b/packages/frontend/core/src/components/hooks/use-block-suite-workspace-page.ts
index 562266e2dc..b833e2d672 100644
--- a/packages/frontend/core/src/components/hooks/use-block-suite-workspace-page.ts
+++ b/packages/frontend/core/src/components/hooks/use-block-suite-workspace-page.ts
@@ -16,7 +16,7 @@ export function useDocCollectionPage(
useEffect(() => {
const group = new DisposableGroup();
group.add(
- docCollection.slots.docAdded.on(id => {
+ docCollection.slots.docCreated.on(id => {
if (pageId === id) {
setPage(docCollection.getDoc(id));
}
diff --git a/packages/frontend/core/src/components/page-list/use-block-suite-workspace-page.ts b/packages/frontend/core/src/components/page-list/use-block-suite-workspace-page.ts
index b7d2833af6..9438744a53 100644
--- a/packages/frontend/core/src/components/page-list/use-block-suite-workspace-page.ts
+++ b/packages/frontend/core/src/components/page-list/use-block-suite-workspace-page.ts
@@ -16,7 +16,7 @@ export function useDocCollectionPage(
useEffect(() => {
const group = new DisposableGroup();
group.add(
- docCollection.slots.docAdded.on(id => {
+ docCollection.slots.docCreated.on(id => {
if (pageId === id) {
setPage(docCollection.getDoc(id));
}