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)
145
147
***Targets:** Usually `entity` (the current entity instance).
148
+
***Automatic Cleanup:** Subscriptions created via `on()` are automatically removed when the Shadow Object is destroyed.
146
149
147
150
#### Listening to View Events
148
151
To listen to events dispatched from the DOM (View Layer), listen to the special event name `'onViewEvent'` on the `entity` target.
149
152
150
153
```typescript
151
-
on(entity, 'onViewEvent', (type, data) => {
154
+
// Implicitly listens on the entity
155
+
on('onViewEvent', (type, data) => {
152
156
if (type==='click') {
153
157
console.log('Clicked!', data);
154
158
}
155
159
});
160
+
161
+
// Explicit target (equivalent to above)
162
+
on(entity, 'onViewEvent', (type, data) => {
163
+
// ...
164
+
});
156
165
```
157
166
158
167
### `once(target, eventName, callback)`
159
168
160
-
Same as `on`, but the listener is automatically removed after the first trigger.
169
+
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