-
Notifications
You must be signed in to change notification settings - Fork 54
Clarify when details should go on events vs targets #585
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 10 commits
0985dde
9337eb6
1193cfa
4c962eb
209d533
0d037b5
0c3916f
726b82f
c3ab2f1
3459c82
3bc1e59
9d24b6b
6debdb7
20d7467
fb77d03
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2556,12 +2556,37 @@ as it implies that it's possible to dispatch an event asynchronously. | |
| All events are dispatched synchronously. | ||
| What is more often implied by "asynchronous event" is to defer firing an event. | ||
|
|
||
| <h3 id="state-and-subclassing">Use plain {{Event}}s for state</h3> | ||
| <h3 id="state-and-subclassing">Put state on {{Event/target}} objects rather than {{Event}}s</h3> | ||
|
|
||
| Where possible, use a plain {{Event}} with a specified `type`, | ||
| and capture any state information in the {{Event/target}} object. | ||
| Put state on the {{Event/target}} | ||
| and use events to signal updates to that state, | ||
| rather than having state on {{Event}} objects. | ||
|
|
||
| It's usually not necessary to create new subclasses of {{Event}}. | ||
| <div class="note"> | ||
|
||
| Having state on the {{Event/target}} object can used to determine the current state, | ||
| without waiting for the next event. | ||
| This is particularly useful if there's a final state, | ||
| where there will be no further events. | ||
| </div> | ||
jakearchibald marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| It's usually not necessary to create new subclasses of {{Event}}, | ||
| but they can be used to provide information relating to how the state change occurred. | ||
|
|
||
| <div class="example"> | ||
| Properties on {{HTMLInputElement}}, | ||
| such as {{HTMLInputElement/value}}, | ||
| provide the state of the input. | ||
| Properties on {{InputEvent}}, | ||
| such as {{InputEvent/inputType}}, | ||
| describe the nature of an update to the state. | ||
| </div> | ||
|
|
||
| In some exceptional cases, where maintaining state on an object is expensive, | ||
| the state may be placed on the {{Event}} instances, | ||
| allowing {{EventTarget/addEventListener}} and {{EventTarget/removeEventListener}} to signal interest/disinterest in this state. | ||
| Although, other patterns should be considered, | ||
| such as retuning an {{EventTarget}} from a function, | ||
| where the function call is a similar signal of interest. | ||
|
||
|
|
||
| <h3 id="events-vs-observers">Use Events and Observers appropriately</h3> | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The previous heading seemed… incomplete.