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
*`on(event: string | symbol | string[], callback: Listener): void` (implicitly uses `entity` as target)
149
151
***Targets:** Usually `entity` (the current entity instance).
152
+
***Automatic Cleanup:** Subscriptions created via `on()` are automatically removed when the Shadow Object is destroyed.
150
153
151
154
#### Listening to View Events
152
155
To listen to events dispatched from the DOM (View Layer), listen to the special event name `'onViewEvent'` on the `entity` target.
153
156
154
157
```typescript
155
-
on(entity, 'onViewEvent', (type, data) => {
158
+
// Implicitly listens on the entity
159
+
on('onViewEvent', (type, data) => {
156
160
if (type==='click') {
157
161
console.log('Clicked!', data);
158
162
}
159
163
});
164
+
165
+
// Explicit target (equivalent to above)
166
+
on(entity, 'onViewEvent', (type, data) => {
167
+
// ...
168
+
});
160
169
```
161
170
162
171
### `once(target, eventName, callback)`
163
172
164
-
Same as `on`, but the listener is automatically removed after the first trigger.
173
+
Same as `on`, but the listener is automatically removed after the first trigger. Like `on`, if the first argument is a string, symbol, or array of strings/symbols, the `entity` is used as the event target.
0 commit comments