mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-06 11:59:51 +08:00
chore(editor): remove unused awareness slot (#9640)
This commit is contained in:
@@ -1,4 +1,3 @@
|
|||||||
import { Slot } from '@blocksuite/global/utils';
|
|
||||||
import type { Awareness } from 'y-protocols/awareness.js';
|
import type { Awareness } from 'y-protocols/awareness.js';
|
||||||
|
|
||||||
export interface UserInfo {
|
export interface UserInfo {
|
||||||
@@ -11,7 +10,6 @@ type UserSelection = Array<Record<string, unknown>>;
|
|||||||
export type RawAwarenessState = {
|
export type RawAwarenessState = {
|
||||||
user?: UserInfo;
|
user?: UserInfo;
|
||||||
color?: string;
|
color?: string;
|
||||||
// use v2 to avoid crush on old clients
|
|
||||||
selectionV2: Record<string, UserSelection>;
|
selectionV2: Record<string, UserSelection>;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -22,51 +20,14 @@ export interface AwarenessEvent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class AwarenessStore {
|
export class AwarenessStore {
|
||||||
private readonly _onAwarenessChange = (diff: {
|
|
||||||
added: number[];
|
|
||||||
removed: number[];
|
|
||||||
updated: number[];
|
|
||||||
}) => {
|
|
||||||
const { added, removed, updated } = diff;
|
|
||||||
|
|
||||||
const states = this.getStates();
|
|
||||||
added.forEach(id => {
|
|
||||||
this.slots.update.emit({
|
|
||||||
id,
|
|
||||||
type: 'add',
|
|
||||||
state: states.get(id),
|
|
||||||
});
|
|
||||||
});
|
|
||||||
updated.forEach(id => {
|
|
||||||
this.slots.update.emit({
|
|
||||||
id,
|
|
||||||
type: 'update',
|
|
||||||
state: states.get(id),
|
|
||||||
});
|
|
||||||
});
|
|
||||||
removed.forEach(id => {
|
|
||||||
this.slots.update.emit({
|
|
||||||
id,
|
|
||||||
type: 'remove',
|
|
||||||
});
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
readonly awareness: Awareness;
|
readonly awareness: Awareness;
|
||||||
|
|
||||||
readonly slots = {
|
|
||||||
update: new Slot<AwarenessEvent>(),
|
|
||||||
};
|
|
||||||
|
|
||||||
constructor(awareness: Awareness) {
|
constructor(awareness: Awareness) {
|
||||||
this.awareness = awareness;
|
this.awareness = awareness;
|
||||||
this.awareness.on('change', this._onAwarenessChange);
|
|
||||||
this.awareness.setLocalStateField('selectionV2', {});
|
this.awareness.setLocalStateField('selectionV2', {});
|
||||||
}
|
}
|
||||||
|
|
||||||
destroy() {
|
destroy() {
|
||||||
this.awareness.off('change', this._onAwarenessChange);
|
|
||||||
this.slots.update.dispose();
|
|
||||||
this.awareness.destroy();
|
this.awareness.destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user