You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Learn how to create workspace contexts that manage shared state and enable communication between extensions in a workspace.
3
+
Workspace Contexts manages shared state and enables communication between extensions in a workspace.
4
4
---
5
5
6
6
# Workspace Context
7
7
8
-
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.
8
+
Workspace Contexts serve as the central communication hub for workspace extensions, providing shared state management within the boundaries of the Workspace. They enable different Workspace components to interact through a common data layer.
9
9
10
10
## Purpose
11
11
12
12
Workspace Contexts provide:
13
13
14
-
-**Shared state** scoped to a specific workspace instance
15
-
-**Communication layer** between extensions in the workspace
16
-
-**Entity lifecycle management** for workspace data
@@ -39,7 +35,7 @@ Workspace Contexts are automatically scoped to their workspace. Extensions in di
39
35
```
40
36
{% endcode %}
41
37
42
-
## Implementation
38
+
## API Implementation
43
39
44
40
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:
45
41
@@ -50,7 +46,7 @@ import { UmbContextBase } from '@umbraco-cms/backoffice/class-api';
'my.extension.alias', // Must match manifest alias
77
+
'example.workspaceContext.counter', // Must match manifest alias
87
78
);
88
79
```
89
80
90
-
## Workspace Lifecycle
91
-
92
-
### Initialization
93
-
94
-
- Created when workspace loads
95
-
- Available to all extensions within that workspace
96
-
- Destroyed when workspace closes
97
-
98
-
### Scoping
99
-
100
-
- Context instances are isolated per workspace
101
-
- Extensions can only access contexts from their own workspace
102
-
- Context requests automatically scope to the nearest workspace
103
-
104
-
### Conditions
105
-
106
-
Workspace contexts only initialize when their conditions match:
107
-
108
-
```typescript
109
-
conditions: [
110
-
{
111
-
alias: UMB_WORKSPACE_CONDITION_ALIAS,
112
-
match: 'Umb.Workspace.Document', // Only available in document workspaces
113
-
},
114
-
],
115
-
```
116
-
117
-
## Entity Data Patterns
81
+
When declaring a Workspace Context, always use `'UmbWorkspaceContext'` as the first parameter in your Context Token to ensure proper context isolation.
Copy file name to clipboardExpand all lines: 17/umbraco-cms/customizing/foundation/states.md
+10-6Lines changed: 10 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,19 +1,23 @@
1
1
---
2
2
description: >-
3
3
Make reactivity with Umbraco States, enabling you to provide a value that
4
-
multiple others can observe and thereby be updated when the value changes.
4
+
others can observe and thereby be updated when the value changes.
5
5
---
6
6
7
7
# States
8
8
9
-
An Umbraco State is a container for a value, it enables you to create [Observables](states.md#observables), which is the name of a hook into the States value — An Observable can then be Observed, such observation provides the current value and if the value of the State changes they will all be updated accordingly.
10
-
11
-
A typical use case is when you need to implement reactivity across class instances. For example, a State is in a Context and the Observer is a Element. For a concrete example, see the [Extension Type Workspace Context](../extending-overview/extension-types/workspaces/workspace-context.md) article.
12
-
13
9
{% hint style="info" %}
14
-
Umbraco States are not relevant when dealing with the reactivity of a Web Component. For that, see the [Lit Element](lit-element.md) article.
10
+
Umbraco States are not relevant when dealing with the reactivity of a Web Component. For more information, see the [Lit Element](lit-element.md) article.
15
11
{% endhint %}
16
12
13
+
An Umbraco State is a container for a value. You create [Observables](../foundation/states.md#observe), which is the name of a hook into the State's value. An Observable can then be observed, providing the current value, and if the value of the State changes, all Observables will be updated accordingly.
14
+
15
+
A typical use case is to bring reactivity across class instances. For example, a Context may provide a value that an Element needs to utilize.
16
+
17
+
In this case, the Context would implement a State and an Observable of it. The Element would then observe the Observable of the Context.
18
+
19
+
You can see an example of this pattern in the [Extension Type Workspace Context](../extending-overview/extension-types/workspaces/workspace-context.md) article.
20
+
17
21
The example below demonstrates the basics of working with a State and observing its changes:
0 commit comments