惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

G
Google Developers Blog
S
Schneier on Security
The Hacker News
The Hacker News
P
Proofpoint News Feed
Spread Privacy
Spread Privacy
L
LINUX DO - 热门话题
L
Lohrmann on Cybersecurity
I
Intezer
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Schneier on Security
Schneier on Security
Security Latest
Security Latest
AWS News Blog
AWS News Blog
B
Blog RSS Feed
Microsoft Security Blog
Microsoft Security Blog
有赞技术团队
有赞技术团队
博客园 - 叶小钗
The Last Watchdog
The Last Watchdog
O
OpenAI News
月光博客
月光博客
Hacker News: Ask HN
Hacker News: Ask HN
阮一峰的网络日志
阮一峰的网络日志
S
Security @ Cisco Blogs
Google Online Security Blog
Google Online Security Blog
云风的 BLOG
云风的 BLOG
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Latest news
Latest news
P
Palo Alto Networks Blog
Last Week in AI
Last Week in AI
M
MIT News - Artificial intelligence
Google DeepMind News
Google DeepMind News
P
Proofpoint News Feed
C
CERT Recently Published Vulnerability Notes
Apple Machine Learning Research
Apple Machine Learning Research
U
Unit 42
PCI Perspectives
PCI Perspectives
博客园 - 聂微东
SecWiki News
SecWiki News
宝玉的分享
宝玉的分享
Forbes - Security
Forbes - Security
H
Heimdal Security Blog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Hugging Face - Blog
Hugging Face - Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
T
Troy Hunt's Blog
博客园 - 三生石上(FineUI控件)
Application and Cybersecurity Blog
Application and Cybersecurity Blog
罗磊的独立博客
WordPress大学
WordPress大学
D
Darknet – Hacking Tools, Hacker News & Cyber Security

Recent Commits to design-principles:main

Event names should use the present tense (#592) Disambiguate when to add global event handlers (#612) · w3ctag/design-principles@41fee41 Handle non-fully-active documents (#597) chore: fix bikeshed warning about multiple definitions of the <a> ele… · w3ctag/design-principles@6ec7e11 Guidance on extensibility patterns: main spec revision vs registries … Un-escape ampersands in a URL to avoid a bikeshed bug. · w3ctag/design-principles@031a3de Trim trailing whitespace. Rewrite the "removing features" section, incorporating "Support Exist… · w3ctag/design-principles@62fc770 Replace asking for users for consent with designing for user intent (… Avoid abbreviations generally (#600) · w3ctag/design-principles@9fc15ba Add principles for task sources (#590) · w3ctag/design-principles@444a329 Update ethical-web-principles links and bibrefs (#601) · w3ctag/design-principles@63b43c9 Clean up link-defaults. · w3ctag/design-principles@993e58e Remove trailing whitespace (#593) · w3ctag/design-principles@98f4a02 Ignore index.html at the root. (#586) Fix example in Keep attributes in sync (#591) · w3ctag/design-principles@afb192e Remove notion of asking for consent to reveal AT use (#589) · w3ctag/design-principles@c35b9cd Reference HTTP WG style guide (#587) · w3ctag/design-principles@81e3ff2 Add 'Choose the Appropriate WebIDL Construct for Data and Behavior' (…
Clarify when details should go on events vs targets (#585) · w3ctag/design-principles@79c2b78
jakearchibal · 2025-10-23 · via Recent Commits to design-principles:main
Original file line numberDiff line numberDiff line change

@@ -2585,12 +2585,59 @@ as it implies that it's possible to dispatch an event asynchronously.

25852585

All events are dispatched synchronously.

25862586

What is more often implied by "asynchronous event" is to defer firing an event.

25872587
2588-

<h3 id="state-and-subclassing">Use plain {{Event}}s for state</h3>

2588+

<h3 id="state-and-subclassing">Put state on {{Event/target}} objects rather than {{Event}}s</h3>

25892589
2590-

Where possible, use a plain {{Event}} with a specified `type`,

2591-

and capture any state information in the {{Event/target}} object.

2590+

Put state on the {{Event/target}}

2591+

and use events to signal updates to that state,

2592+

rather than having state on {{Event}} objects.

25922593
2593-

It's usually not necessary to create new subclasses of {{Event}}.

2594+

Having state on the {{Event/target}} object can used to determine the current state,

2595+

without waiting for the next event.

2596+

This is particularly useful if there's a final state,

2597+

where there will be no further events.

2598+
2599+

It's usually not necessary to create new subclasses of {{Event}},

2600+

but they can be used to provide information relating to how the state change occurred.

2601+
2602+

<div class="example">

2603+

Properties on {{HTMLInputElement}},

2604+

such as {{HTMLInputElement/value}},

2605+

provide the state of the input.

2606+

Properties on {{InputEvent}},

2607+

such as {{InputEvent/inputType}},

2608+

describe the nature of an update to the state.

2609+

</div>

2610+
2611+

In some exceptional cases, where maintaining state on an object is expensive,

2612+

other patterns may be considered,

2613+

such as returning an {{EventTarget}} from a function call,

2614+

where the function call is a signal of interest.

2615+
2616+

<div class="example">

2617+

Using an imaginary `dataUsage` API that reports the amount of data an environment has used, the recommended pattern is:

2618+
2619+

<pre highlight="js">

2620+

self.dataUsage.addEventListener('change', () => {

2621+

console.log(self.dataUsage.bytesReceived);

2622+

});

2623+

</pre>

2624+
2625+

Where `bytesReceived` exists on the `dataUsage` {{EventTarget}},

2626+

rather than the {{Event}}.

2627+
2628+

If maintaining the state on this object is too expensive, this pattern may be considered:

2629+
2630+

<pre highlight="js">

2631+

const dataUsage = await self.monitorDataUsage();

2632+
2633+

dataUsage.addEventListener('change', () => {

2634+

console.log(dataUsage.bytesReceived);

2635+

});

2636+

</pre>

2637+
2638+

In this pattern, the call to `monitorDataUsage` signals interest in the data,

2639+

and the state does not need to be updated until `monitorDataUsage` is called.

2640+

</div>

25942641
25952642

<h3 id="events-vs-observers">Use Events and Observers appropriately</h3>

25962643