mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-24 05:07:06 +08:00
feat(editor): replace slot with rxjs subject (#10768)
This commit is contained in:
@@ -108,7 +108,7 @@ export class DocsPanel extends WithDisposable(ShadowlessElement) {
|
||||
});
|
||||
|
||||
this.disposables.add(
|
||||
this.editor.doc.workspace.slots.docListUpdated.on(() => {
|
||||
this.editor.doc.workspace.slots.docListUpdated.subscribe(() => {
|
||||
this.requestUpdate();
|
||||
})
|
||||
);
|
||||
|
||||
@@ -732,7 +732,7 @@ export class StarterDebugMenu extends ShadowlessElement {
|
||||
}
|
||||
|
||||
override firstUpdated() {
|
||||
this.doc.slots.historyUpdated.on(() => {
|
||||
this.doc.slots.historyUpdated.subscribe(() => {
|
||||
this._canUndo = this.doc.canUndo;
|
||||
this._canRedo = this.doc.canRedo;
|
||||
});
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { toast } from '@blocksuite/affine/components/toast';
|
||||
import { Slot } from '@blocksuite/affine/global/slot';
|
||||
import {
|
||||
ColorScheme,
|
||||
type DocMode,
|
||||
@@ -17,6 +16,7 @@ import {
|
||||
import { type Workspace } from '@blocksuite/affine/store';
|
||||
import type { TestAffineEditorContainer } from '@blocksuite/integration-test';
|
||||
import { Signal, signal } from '@preact/signals-core';
|
||||
import { Subject } from 'rxjs';
|
||||
|
||||
function getModeFromStorage() {
|
||||
const mapJson = localStorage.getItem('playground:docMode');
|
||||
@@ -37,7 +37,7 @@ export function removeModeFromStorage(docId: string) {
|
||||
}
|
||||
|
||||
const DEFAULT_MODE: DocMode = 'page';
|
||||
const slotMap = new Map<string, Slot<DocMode>>();
|
||||
const slotMap = new Map<string, Subject<DocMode>>();
|
||||
|
||||
export function mockDocModeService(editor: TestAffineEditorContainer) {
|
||||
const getEditorModeCallback: () => DocMode = () => editor.mode;
|
||||
@@ -54,9 +54,9 @@ export function mockDocModeService(editor: TestAffineEditorContainer) {
|
||||
},
|
||||
onPrimaryModeChange: (handler: (mode: DocMode) => void, docId: string) => {
|
||||
if (!slotMap.get(docId)) {
|
||||
slotMap.set(docId, new Slot());
|
||||
slotMap.set(docId, new Subject());
|
||||
}
|
||||
return slotMap.get(docId)!.on(handler);
|
||||
return slotMap.get(docId)!.subscribe(handler);
|
||||
},
|
||||
getEditorMode: () => {
|
||||
return getEditorModeCallback();
|
||||
@@ -68,7 +68,7 @@ export function mockDocModeService(editor: TestAffineEditorContainer) {
|
||||
const modeMap = getModeFromStorage();
|
||||
modeMap.set(docId, mode);
|
||||
saveModeToStorage(modeMap);
|
||||
slotMap.get(docId)?.emit(mode);
|
||||
slotMap.get(docId)?.next(mode);
|
||||
},
|
||||
togglePrimaryMode: (docId: string) => {
|
||||
const mode =
|
||||
|
||||
Reference in New Issue
Block a user