Skip to content

Commit

Permalink
refactor(editor): merge docCreated and docAdded slot
Browse files Browse the repository at this point in the history
  • Loading branch information
Saul-Mirone committed Jan 2, 2025
1 parent f2906bc commit 75066ef
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 8 deletions.
2 changes: 1 addition & 1 deletion blocksuite/affine/block-data-view/src/data-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 1 addition & 3 deletions blocksuite/framework/store/src/store/collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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>(),
Expand Down Expand Up @@ -163,7 +162,7 @@ export class DocCollection {
idGenerator: this.idGenerator,
});
this.blockCollections.set(doc.id, doc);
this.slots.docAdded.emit(doc.id);
this.slots.docCreated.emit(doc.id);
});

this.meta.docMetaUpdated.on(() => this.slots.docUpdated.emit());
Expand Down Expand Up @@ -209,7 +208,6 @@ export class DocCollection {
createDate: Date.now(),
tags: [],
});
this.slots.docCreated.emit(docId);
return this.getDoc(docId, { query }) as Doc;
}

Expand Down
2 changes: 1 addition & 1 deletion blocksuite/playground/apps/starter/utils/collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,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
Expand Down
2 changes: 1 addition & 1 deletion blocksuite/tests-legacy/utils/actions/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down

0 comments on commit 75066ef

Please sign in to comment.