Principle:AFK surf Open agent Scope Branching
| 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]);
}