There can be more than Notion and Miro. AFFiNE(pronounced [ə‘fain]) is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.
TypeScript appcrdteditorelectronknowledge-basemarkdownmironotesnotionnotion-alternativerustrust-langrust-languagetabletableviewwhiteboardwikiworkspace
refactor(editor): remove redundant getOptional for gfx (#10142)
Yifeng Wang26de7a56fd71
diff --git a/blocksuite/affine/widget-remote-selection/src/doc/doc-remote-selection.ts b/blocksuite/affine/widget-remote-selection/src/doc/doc-remote-selection.tsindex 378a79e8eb..3cf1bdc063 100644--- a/blocksuite/affine/widget-remote-selection/src/doc/doc-remote-selection.ts+++ b/blocksuite/affine/widget-remote-selection/src/doc/doc-remote-selection.ts@@ -14,7 +14,7 @@ import {TextSelection,WidgetComponent,} from '@blocksuite/block-std';-import { GfxController } from '@blocksuite/block-std/gfx';+import { GfxControllerIdentifier } from '@blocksuite/block-std/gfx';import { throttle } from '@blocksuite/global/utils';import type { BaseSelection, UserInfo } from '@blocksuite/store';import { computed, effect } from '@preact/signals-core';@@ -308,8 +308,7 @@ export class AffineDocRemoteSelectionWidget extends WidgetComponent {}));- const gfx = this.std.getOptional(GfxController);- if (!gfx) return;+ const gfx = this.std.get(GfxControllerIdentifier);this.disposables.add(gfx.viewport.viewportUpdated.on(() => {const selections = this._remoteSelections.peek();diff --git a/blocksuite/affine/widget-scroll-anchoring/src/scroll-anchoring.ts b/blocksuite/affine/widget-scroll-anchoring/src/scroll-anchoring.tsindex 259ea599c1..17f38507a9 100644--- a/blocksuite/affine/widget-scroll-anchoring/src/scroll-anchoring.ts+++ b/blocksuite/affine/widget-scroll-anchoring/src/scroll-anchoring.ts@@ -68,9 +68,7 @@ export class AffineScrollAnchoringWidget extends WidgetComponent {);#getBoundsInEdgeless() {- const controller = this.std.getOptional(GfxControllerIdentifier);- if (!controller) return;-+ const controller = this.std.get(GfxControllerIdentifier);const bounds = this.anchorBounds$.peek();if (!bounds) return;@@ -96,9 +94,7 @@ export class AffineScrollAnchoringWidget extends WidgetComponent {}#moveToAnchorInEdgeless(id: string) {- const controller = this.std.getOptional(GfxControllerIdentifier);- if (!controller) return;-+ const controller = this.std.get(GfxControllerIdentifier);const surface = controller.surface;if (!surface) return;@@ -194,12 +190,10 @@ export class AffineScrollAnchoringWidget extends WidgetComponent {});// In edgeless- const controler = this.std.getOptional(GfxControllerIdentifier);- if (controler) {- this.disposables.add(- controler.viewport.viewportUpdated.on(this.#requestUpdateFn)- );- }+ const controler = this.std.get(GfxControllerIdentifier);+ this.disposables.add(+ controler.viewport.viewportUpdated.on(this.#requestUpdateFn)+ );this.disposables.add(this.anchor$.subscribe(anchor => {diff --git a/blocksuite/blocks/src/root-block/widgets/linked-doc/index.ts b/blocksuite/blocks/src/root-block/widgets/linked-doc/index.tsindex 2036d0fb5c..c116bc2e10 100644--- a/blocksuite/blocks/src/root-block/widgets/linked-doc/index.ts+++ b/blocksuite/blocks/src/root-block/widgets/linked-doc/index.ts@@ -7,7 +7,7 @@ import { FeatureFlagService } from '@blocksuite/affine-shared/services';import { getViewportElement } from '@blocksuite/affine-shared/utils';import type { BlockComponent } from '@blocksuite/block-std';import { BLOCK_ID_ATTR, WidgetComponent } from '@blocksuite/block-std';-import { GfxController } from '@blocksuite/block-std/gfx';+import { GfxControllerIdentifier } from '@blocksuite/block-std/gfx';import { IS_MOBILE } from '@blocksuite/global/env';import {INLINE_ROOT_ATTR,@@ -197,8 +197,7 @@ export class AffineLinkedDocWidget extends WidgetComponent<}private _watchViewportChange() {- const gfx = this.std.getOptional(GfxController);- if (!gfx) return;+ const gfx = this.std.get(GfxControllerIdentifier);this.disposables.add(gfx.viewport.viewportUpdated.on(() => {this._updateInputRects();diff --git a/blocksuite/blocks/src/root-block/widgets/linked-doc/linked-doc-popover.ts b/blocksuite/blocks/src/root-block/widgets/linked-doc/linked-doc-popover.tsindex 8f02960aea..6bf80d75e8 100644--- a/blocksuite/blocks/src/root-block/widgets/linked-doc/linked-doc-popover.ts+++ b/blocksuite/blocks/src/root-block/widgets/linked-doc/linked-doc-popover.ts@@ -12,7 +12,7 @@ import {getViewportElement,} from '@blocksuite/affine-shared/utils';import { PropTypes, requiredProperties } from '@blocksuite/block-std';-import { GfxController } from '@blocksuite/block-std/gfx';+import { GfxControllerIdentifier } from '@blocksuite/block-std/gfx';import {SignalWatcher,throttle,@@ -341,10 +341,8 @@ export class LinkedDocPopover extends SignalWatcher();}- const gfx = this.context.std.getOptional(GfxController);- if (gfx) {- this.disposables.add(gfx.viewport.viewportUpdated.on(updatePosition));- }+ const gfx = this.context.std.get(GfxControllerIdentifier);+ this.disposables.add(gfx.viewport.viewportUpdated.on(updatePosition));updatePosition();}