feat(editor): replace slot with rxjs subject (#10768)

This commit is contained in:
Mirone
2025-03-12 11:29:24 +09:00
committed by GitHub
parent 19f978d9aa
commit cd63e0ed8b
302 changed files with 1405 additions and 1251 deletions
@@ -1,4 +1,5 @@
import { DisposableGroup, Slot } from '@blocksuite/global/slot';
import { DisposableGroup } from '@blocksuite/global/disposable';
import { Subject } from 'rxjs';
import type { BlockStdScope } from '../scope/block-std-scope';
import { LifeCycleWatcher } from './lifecycle-watcher';
@@ -9,10 +10,10 @@ export class EditorLifeCycleExtension extends LifeCycleWatcher {
disposables = new DisposableGroup();
readonly slots = {
created: new Slot(),
mounted: new Slot(),
rendered: new Slot(),
unmounted: new Slot(),
created: new Subject<void>(),
mounted: new Subject<void>(),
rendered: new Subject<void>(),
unmounted: new Subject<void>(),
};
constructor(override readonly std: BlockStdScope) {
@@ -26,22 +27,22 @@ export class EditorLifeCycleExtension extends LifeCycleWatcher {
override created() {
super.created();
this.slots.created.emit();
this.slots.created.next();
}
override mounted() {
super.mounted();
this.slots.mounted.emit();
this.slots.mounted.next();
}
override rendered() {
super.rendered();
this.slots.rendered.emit();
this.slots.rendered.next();
}
override unmounted() {
super.unmounted();
this.slots.unmounted.emit();
this.slots.unmounted.next();
this.disposables.dispose();
}
@@ -1,6 +1,6 @@
import type { Container } from '@blocksuite/global/di';
import { DisposableGroup } from '@blocksuite/global/disposable';
import { BlockSuiteError, ErrorCode } from '@blocksuite/global/exceptions';
import { DisposableGroup } from '@blocksuite/global/slot';
import { Extension } from '@blocksuite/store';
import type { EventName, UIEventHandler } from '../event/index.js';
@@ -109,12 +109,12 @@ export abstract class BlockService extends Extension {
// life cycle end
mounted() {
this.specSlots.mounted.emit({ service: this });
this.specSlots.mounted.next({ service: this });
}
unmounted() {
this.dispose();
this.specSlots.unmounted.emit({ service: this });
this.specSlots.unmounted.next({ service: this });
}
// event handlers end
}