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
Copy file name to clipboardExpand all lines: projects/www/src/app/pages/guide/signals/signal-store/events.md
+145Lines changed: 145 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -458,3 +458,148 @@ export class BookSearch {
458
458
```
459
459
460
460
</ngrx-code-example>
461
+
462
+
## Scoped Events
463
+
464
+
By default, the `Dispatcher` and `Events` services operate in a global scope where all dispatched events are handled application-wide.
465
+
In some cases, event handling should be isolated to a particular feature or component subtree.
466
+
Typical examples include local state management scenarios where events should stay within a specific feature, or micro-frontend architectures where each remote module needs its own isolated event scope.
467
+
To support this, the Events plugin provides a built-in mechanism for scoped events.
468
+
469
+
### Creating Local Scope
470
+
471
+
A new event scope can be created at a feature or component level by using the `provideDispatcher()` function.
472
+
Any events dispatched inside this boundary will belong to the local scope unless explicitly forwarded.
473
+
474
+
When dispatching an event, the scope can be explicitly selected using the dispatch configuration:
475
+
476
+
-`self` (default): An event dispatched and handled only within the local scope.
477
+
-`parent`: An event is forwarded to the parent dispatcher.
478
+
-`global`: An event is forwarded to the global dispatcher.
Event flow within scopes follows a hierarchical visibility rule, which means that `Events` service receives events dispatched in their own scope and events dispatched in any parent scope, including the global scope.
519
+
On the other hand, events dispatched locally are not visible to ancestor scopes.
520
+
521
+
<ngrx-docs-alerttype="help">
522
+
523
+
When using `Dispatcher`, the scope can be provided as a second argument of the `dispatch` method.
0 commit comments