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: docs/content/features/events.md
+67-2Lines changed: 67 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -145,7 +145,7 @@ public void Add()
145
145
`Add` triggers the event asynchronously, so the button that triggers this action will be disabled until the action is done. The event execution won't be connected with the action's pipeline and will be run on its own.
146
146
147
147
148
-
## Events scope
148
+
## Event scope
149
149
150
150
By default, the events are dispatched only to their parent component. To publish a global event use the following
151
151
method:
@@ -154,6 +154,12 @@ method:
154
154
Dispatch(newShowMessage(Content), Scope.Global);
155
155
```
156
156
157
+
or
158
+
159
+
```c#
160
+
DispatchGlobal(newShowMessage(Content));
161
+
```
162
+
157
163
Any component that subscribes for `ShowMessage` will be notified, no matter the component's location.
158
164
159
165
## Inlined subscription
@@ -193,4 +199,63 @@ public class ProductList : HydroComponent
193
199
// When ProductAddedEvent occurs, component will be rerendered
194
200
}
195
201
}
196
-
```
202
+
```
203
+
204
+
## Event subject
205
+
206
+
There might be a situation where you want to filter the events you receive in your subscription handler. It means that
207
+
your component subscribes to an event, but handles it only when it contains a certain flag. That flag can be any string
208
+
and is called a `subject`.
209
+
210
+
You can imagine a page with multiple lists of todos. Each list is a Hydro component that listens to events like `TodoAdded`,
211
+
`TodoRemoved` or `TodoEdited`. When a todo is removed on one list, you don't want all the other lists to receive and react to that event, but only
212
+
the list that contained that todo item. This is solved in Hydro by using `subject` parameter, which in this case will be the list's id.
213
+
When `TodoAdded`, `TodoRemoved` or `TodoEdited` are dispatched, `subject` is set to their list's id. The list component subscribes to those
0 commit comments