mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-12 04:18:54 +00:00
refactor(editor): remove assertExists (#10615)
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import type { DocModeProvider } from '@blocksuite/blocks';
|
||||
import { assertExists } from '@blocksuite/global/utils';
|
||||
import type { TestAffineEditorContainer } from '@blocksuite/integration-test';
|
||||
import type { Doc, Store, Workspace } from '@blocksuite/store';
|
||||
|
||||
@@ -13,14 +12,18 @@ export function getDocFromUrlParams(collection: Workspace, url: URL) {
|
||||
}
|
||||
if (!doc) {
|
||||
const blockCollection = collection.docs.values().next().value as Doc;
|
||||
assertExists(blockCollection, 'Need to create a doc first');
|
||||
if (!blockCollection) {
|
||||
throw new Error('Need to create a doc first');
|
||||
}
|
||||
doc = blockCollection.getStore();
|
||||
}
|
||||
|
||||
doc.load();
|
||||
doc.resetHistory();
|
||||
|
||||
assertExists(doc.root, 'Doc root is not ready');
|
||||
if (!doc.root) {
|
||||
throw new Error('Doc root is not ready');
|
||||
}
|
||||
|
||||
return doc;
|
||||
}
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -8,7 +8,6 @@ import {
|
||||
import { groupTraitKey } from '@blocksuite/data-view';
|
||||
import { propertyPresets } from '@blocksuite/data-view/property-presets';
|
||||
import { viewPresets } from '@blocksuite/data-view/view-presets';
|
||||
import { assertExists } from '@blocksuite/global/utils';
|
||||
import { Text, type Workspace } from '@blocksuite/store';
|
||||
|
||||
import type { InitFn } from './utils.js';
|
||||
@@ -27,7 +26,9 @@ export const database: InitFn = (collection: Workspace, id: string) => {
|
||||
const noteId = doc.addBlock('affine:note', {}, rootId);
|
||||
const pId = doc.addBlock('affine:paragraph', {}, noteId);
|
||||
const model = doc.getBlockById(pId);
|
||||
assertExists(model);
|
||||
if (!model) {
|
||||
throw new Error('model is not found');
|
||||
}
|
||||
const addDatabase = (title: string, group = true) => {
|
||||
const databaseId = doc.addBlock(
|
||||
'affine:database',
|
||||
|
||||
Reference in New Issue
Block a user