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.workspace.docs.forEach(doc => {
|
||||||
this.listenToDoc(doc.getDoc());
|
this.listenToDoc(doc.getDoc());
|
||||||
});
|
});
|
||||||
this.workspace.slots.docAdded.on(id => {
|
this.workspace.slots.docCreated.on(id => {
|
||||||
const doc = this.workspace.getDoc(id);
|
const doc = this.workspace.getDoc(id);
|
||||||
if (doc) {
|
if (doc) {
|
||||||
this.listenToDoc(doc);
|
this.listenToDoc(doc);
|
||||||
|
|||||||
@@ -94,7 +94,6 @@ export class DocCollection {
|
|||||||
meta: DocCollectionMeta;
|
meta: DocCollectionMeta;
|
||||||
|
|
||||||
slots = {
|
slots = {
|
||||||
docAdded: new Slot<string>(),
|
|
||||||
docUpdated: new Slot(),
|
docUpdated: new Slot(),
|
||||||
docRemoved: new Slot<string>(),
|
docRemoved: new Slot<string>(),
|
||||||
docCreated: new Slot<string>(),
|
docCreated: new Slot<string>(),
|
||||||
@@ -163,7 +162,6 @@ export class DocCollection {
|
|||||||
idGenerator: this.idGenerator,
|
idGenerator: this.idGenerator,
|
||||||
});
|
});
|
||||||
this.blockCollections.set(doc.id, doc);
|
this.blockCollections.set(doc.id, doc);
|
||||||
this.slots.docAdded.emit(doc.id);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
this.meta.docMetaUpdated.on(() => this.slots.docUpdated.emit());
|
this.meta.docMetaUpdated.on(() => this.slots.docUpdated.emit());
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ export async function initStarterDocCollection(collection: DocCollection) {
|
|||||||
let firstDoc = firstCollection?.getDoc();
|
let firstDoc = firstCollection?.getDoc();
|
||||||
if (!firstDoc) {
|
if (!firstDoc) {
|
||||||
await new Promise<string>(resolve =>
|
await new Promise<string>(resolve =>
|
||||||
collection.slots.docAdded.once(resolve)
|
collection.slots.docCreated.once(resolve)
|
||||||
);
|
);
|
||||||
const firstCollection = collection.docs.values().next().value as
|
const firstCollection = collection.docs.values().next().value as
|
||||||
| BlockCollection
|
| BlockCollection
|
||||||
|
|||||||
@@ -201,7 +201,7 @@ async function initEmptyEditor({
|
|||||||
window.doc = firstDoc;
|
window.doc = firstDoc;
|
||||||
waitForMountPageEditor(firstDoc).catch;
|
waitForMountPageEditor(firstDoc).catch;
|
||||||
} else {
|
} else {
|
||||||
collection.slots.docAdded.on(docId => {
|
collection.slots.docCreated.on(docId => {
|
||||||
const doc = collection.getDoc(docId);
|
const doc = collection.getDoc(docId);
|
||||||
if (!doc) {
|
if (!doc) {
|
||||||
throw new Error(`Failed to get doc ${docId}`);
|
throw new Error(`Failed to get doc ${docId}`);
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ export function useDocCollectionPage(
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const group = new DisposableGroup();
|
const group = new DisposableGroup();
|
||||||
group.add(
|
group.add(
|
||||||
docCollection.slots.docAdded.on(id => {
|
docCollection.slots.docCreated.on(id => {
|
||||||
if (pageId === id) {
|
if (pageId === id) {
|
||||||
setPage(docCollection.getDoc(id));
|
setPage(docCollection.getDoc(id));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ export function useDocCollectionPage(
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const group = new DisposableGroup();
|
const group = new DisposableGroup();
|
||||||
group.add(
|
group.add(
|
||||||
docCollection.slots.docAdded.on(id => {
|
docCollection.slots.docCreated.on(id => {
|
||||||
if (pageId === id) {
|
if (pageId === id) {
|
||||||
setPage(docCollection.getDoc(id));
|
setPage(docCollection.getDoc(id));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user