Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Principle:AFK surf Open agent Scope Branching

From Leeroopedia
Knowledge Sources
Domains Extensions, Plugin_System, BlockSuite
Last Updated 2026-10-25 00:00 GMT

Overview

Pattern of registering different extensions per view scope inside a single setup hook by branching on context.scope and the validated options.

Description

A view provider's setup hook receives a ViewExtensionContext whose scope is one of page, edgeless, preview-page, preview-edgeless, mobile-page, mobile-edgeless. The hook can branch on scope to register scope-specific extensions (e.g. PageExt only when scope === 'page', EdgelessExt only when scope === 'edgeless) and on the validated options to register conditional extensions (e.g. a dark-mode widget when options.theme === 'dark). context.register accumulates extensions across multiple calls. This keeps the page and edgeless surfaces from loading each other's UI while allowing shared common extensions.

Usage

Apply this principle when a single provider should behave differently per view surface — page vs. edgeless vs. mobile — or per configuration option. Avoid heavy work in setup; defer one-time initialization to effect.

Theoretical Basis

setup is a pure function of (scope, options) → ExtensionType[]. Branching on scope partitions the extension set per surface; branching on options gates optional extensions. The manager calls setup once per scope, so the branch keeps each scope's extension list minimal.

Pseudo-code:

override setup(context, options?) {
  super.setup(context, options);
  context.register([CommonExt]);
  if (context.scope === 'page') context.register([PageExt]);
  else if (context.scope === 'edgeless') context.register([EdgelessExt]);
  if (options?.theme === 'dark') context.register([DarkModeExt]);
}

Related Pages

Implemented By

Uses Heuristic

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment