mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-14 21:27:20 +00:00
refactor(editor): remove assertExists (#10615)
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
import { assertExists } from '@blocksuite/global/utils';
|
||||
import type { AwarenessSource } from '@blocksuite/sync';
|
||||
import type { Awareness } from 'y-protocols/awareness';
|
||||
import {
|
||||
@@ -21,7 +20,9 @@ export class WebSocketAwarenessSource implements AwarenessSource {
|
||||
res.concat(cur)
|
||||
);
|
||||
|
||||
assertExists(this.awareness);
|
||||
if (!this.awareness) {
|
||||
throw new Error('awareness is not found');
|
||||
}
|
||||
const update = encodeAwarenessUpdate(this.awareness, changedClients);
|
||||
this.ws.send(
|
||||
JSON.stringify({
|
||||
@@ -42,12 +43,16 @@ export class WebSocketAwarenessSource implements AwarenessSource {
|
||||
|
||||
if (type === 'update') {
|
||||
const update = data.payload.update;
|
||||
assertExists(this.awareness);
|
||||
if (!this.awareness) {
|
||||
throw new Error('awareness is not found');
|
||||
}
|
||||
applyAwarenessUpdate(this.awareness, new Uint8Array(update), 'remote');
|
||||
}
|
||||
|
||||
if (type === 'connect') {
|
||||
assertExists(this.awareness);
|
||||
if (!this.awareness) {
|
||||
throw new Error('awareness is not found');
|
||||
}
|
||||
this.ws.send(
|
||||
JSON.stringify({
|
||||
channel: 'awareness',
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { assertExists } from '@blocksuite/global/utils';
|
||||
import type { DocSource } from '@blocksuite/sync';
|
||||
import { diffUpdate, encodeStateVectorFromUpdate, mergeUpdates } from 'yjs';
|
||||
|
||||
@@ -69,7 +68,9 @@ export class WebSocketDocSource implements DocSource {
|
||||
}
|
||||
|
||||
const latest = this.docMap.get(docId);
|
||||
assertExists(latest);
|
||||
if (!latest) {
|
||||
throw new Error('latest is not found');
|
||||
}
|
||||
this.ws.send(
|
||||
JSON.stringify({
|
||||
channel: 'doc',
|
||||
|
||||
Reference in New Issue
Block a user