Workspace Context
Learn how to create workspace contexts that manage shared state and enable communication between extensions in a workspace.
Workspace Contexts serve as the central communication hub for workspace extensions, providing shared state management within workspace boundaries. They enable different workspace components to interact through a common data layer.
Purpose
Workspace Contexts provide:
Shared state scoped to a specific workspace instance
Communication layer between extensions in the workspace
Entity lifecycle management for workspace data
Context isolation ensures workspace independence
Manifest
{
type: 'workspaceContext',
name: 'Example Counter Workspace Context',
alias: 'example.workspaceContext.counter',
api: () => import('./counter-workspace-context.js'),
conditions: [
{
alias: UMB_WORKSPACE_CONDITION_ALIAS,
match: 'Umb.Workspace.Document',
},
],
}Implementation
Create a workspace context by extending UmbContextBase and providing a unique context token. Add this to your project to enable shared state management between workspace extensions:
Context Token Pattern
Always use 'UmbWorkspaceContext' as the first parameter in your context token to ensure proper workspace scoping and isolation:
Workspace Lifecycle
Initialization
Created when workspace loads
Available to all extensions within that workspace
Destroyed when workspace closes
Scoping
Context instances are isolated per workspace
Extensions can only access contexts from their own workspace
Context requests automatically scope to the nearest workspace
Conditions
Workspace contexts only initialize when their conditions match:
Entity Data Patterns
Draft State Management
Server Integration
Extension Communication
In Workspace Actions
In Workspace Views
Best Practices
State Encapsulation
Context Token Consistency
Conditional Availability
Only provide contexts when they are meaningful for the workspace type.
Last updated
Was this helpful?