refactor(editor): remove assertExists (#10615)

This commit is contained in:
Saul-Mirone
2025-03-05 00:13:08 +00:00
parent a6692f70aa
commit b8ecfbdae6
106 changed files with 863 additions and 517 deletions

View File

@@ -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',

View File

@@ -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',