mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-22 20:46:38 +08:00
refactor(editor): merge docCreated and docAdded slot (#9489)
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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}`);
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user