refactor(editor): remove unused code (#12142)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Refactor** - Streamlined internal logic for handling block operations to improve efficiency. - Removed unused reactive subject and related code from document handling classes. - Renamed a private initialization method for improved clarity. - **Chores** - Cleaned up redundant code and imports to simplify maintenance. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
@@ -601,9 +601,7 @@ export class Store {
|
|||||||
this._yBlocks.observeDeep(this._handleYEvents);
|
this._yBlocks.observeDeep(this._handleYEvents);
|
||||||
this._yBlocks.forEach((_, id) => {
|
this._yBlocks.forEach((_, id) => {
|
||||||
this._handleYBlockAdd(id, false);
|
this._handleYBlockAdd(id, false);
|
||||||
});
|
|
||||||
|
|
||||||
this._yBlocks.forEach((_, id) => {
|
|
||||||
if (id in this._blocks.peek()) {
|
if (id in this._blocks.peek()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import { Subject } from 'rxjs';
|
|
||||||
import * as Y from 'yjs';
|
import * as Y from 'yjs';
|
||||||
|
|
||||||
import type { YBlock } from '../model/block/types.js';
|
import type { YBlock } from '../model/block/types.js';
|
||||||
@@ -28,7 +27,6 @@ export class TestDoc implements Doc {
|
|||||||
});
|
});
|
||||||
this.rootDoc.getMap('spaces').set(this.id, subDoc);
|
this.rootDoc.getMap('spaces').set(this.id, subDoc);
|
||||||
this._loaded = true;
|
this._loaded = true;
|
||||||
this._onLoadSlot.next();
|
|
||||||
} else {
|
} else {
|
||||||
this._loaded = false;
|
this._loaded = false;
|
||||||
this.rootDoc.on('subdocs', this._onSubdocEvent);
|
this.rootDoc.on('subdocs', this._onSubdocEvent);
|
||||||
@@ -39,8 +37,6 @@ export class TestDoc implements Doc {
|
|||||||
|
|
||||||
private _loaded!: boolean;
|
private _loaded!: boolean;
|
||||||
|
|
||||||
private readonly _onLoadSlot = new Subject<void>();
|
|
||||||
|
|
||||||
private readonly _onSubdocEvent = ({
|
private readonly _onSubdocEvent = ({
|
||||||
loaded,
|
loaded,
|
||||||
}: {
|
}: {
|
||||||
@@ -54,7 +50,6 @@ export class TestDoc implements Doc {
|
|||||||
}
|
}
|
||||||
this.rootDoc.off('subdocs', this._onSubdocEvent);
|
this.rootDoc.off('subdocs', this._onSubdocEvent);
|
||||||
this._loaded = true;
|
this._loaded = true;
|
||||||
this._onLoadSlot.next();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Indicate whether the block tree is ready */
|
/** Indicate whether the block tree is ready */
|
||||||
@@ -132,7 +127,6 @@ export class TestDoc implements Doc {
|
|||||||
|
|
||||||
private _destroy() {
|
private _destroy() {
|
||||||
this._ySpaceDoc.destroy();
|
this._ySpaceDoc.destroy();
|
||||||
this._onLoadSlot.complete();
|
|
||||||
this._loaded = false;
|
this._loaded = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ import {
|
|||||||
type Workspace,
|
type Workspace,
|
||||||
type YBlock,
|
type YBlock,
|
||||||
} from '@blocksuite/affine/store';
|
} from '@blocksuite/affine/store';
|
||||||
import { Subject } from 'rxjs';
|
|
||||||
import { Awareness } from 'y-protocols/awareness.js';
|
import { Awareness } from 'y-protocols/awareness.js';
|
||||||
import * as Y from 'yjs';
|
import * as Y from 'yjs';
|
||||||
|
|
||||||
@@ -24,7 +23,7 @@ export class DocImpl implements Doc {
|
|||||||
|
|
||||||
private readonly _storeMap = new Map<string, Store>();
|
private readonly _storeMap = new Map<string, Store>();
|
||||||
|
|
||||||
private readonly _initSubDoc = () => {
|
private readonly _initSpaceDoc = () => {
|
||||||
{
|
{
|
||||||
// This is a piece of old version compatible code. The old version relies on the subdoc instance on `spaces`.
|
// This is a piece of old version compatible code. The old version relies on the subdoc instance on `spaces`.
|
||||||
// So if there is no subdoc on spaces, we will create it.
|
// So if there is no subdoc on spaces, we will create it.
|
||||||
@@ -47,9 +46,6 @@ export class DocImpl implements Doc {
|
|||||||
|
|
||||||
private _loaded!: boolean;
|
private _loaded!: boolean;
|
||||||
|
|
||||||
// eslint-disable-next-line rxjs/finnish
|
|
||||||
private readonly _onLoadSlot = new Subject();
|
|
||||||
|
|
||||||
/** Indicate whether the block tree is ready */
|
/** Indicate whether the block tree is ready */
|
||||||
private _ready = false;
|
private _ready = false;
|
||||||
|
|
||||||
@@ -104,7 +100,7 @@ export class DocImpl implements Doc {
|
|||||||
constructor({ id, collection, doc }: DocOptions) {
|
constructor({ id, collection, doc }: DocOptions) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.rootDoc = doc;
|
this.rootDoc = doc;
|
||||||
this._ySpaceDoc = this._initSubDoc() as Y.Doc;
|
this._ySpaceDoc = this._initSpaceDoc() as Y.Doc;
|
||||||
this.awarenessStore = new AwarenessStore(new Awareness(this._ySpaceDoc));
|
this.awarenessStore = new AwarenessStore(new Awareness(this._ySpaceDoc));
|
||||||
|
|
||||||
this._yBlocks = this._ySpaceDoc.getMap('blocks');
|
this._yBlocks = this._ySpaceDoc.getMap('blocks');
|
||||||
@@ -127,7 +123,6 @@ export class DocImpl implements Doc {
|
|||||||
private _destroy() {
|
private _destroy() {
|
||||||
this.awarenessStore.destroy();
|
this.awarenessStore.destroy();
|
||||||
this._ySpaceDoc.destroy();
|
this._ySpaceDoc.destroy();
|
||||||
this._onLoadSlot.unsubscribe();
|
|
||||||
this._loaded = false;
|
this._loaded = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user