Skip to content
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

New principle: Events should only fire during actual state transitions #483

Open
LeaVerou opened this issue Mar 25, 2024 · 3 comments
Open
Assignees
Labels
Status: Consensus to write We have TAG consensus about the principle but someone needs to write it (see "To Write" project) Topic: Event Design
Projects

Comments

@LeaVerou
Copy link
Member

This was brought up in our discussion of w3ctag/design-reviews#843

It started as a naming observation: change is far more common than update in event names. Then we realized that update may be more appropriate when the event invocation happens regardless of actual state change. However, that does not seem to be followed by the web platform, e.g. reading the MDN docs on timeupdate, it sounds like it would only fire when the time has actually updated.

Regardless, events that fire when things have not actually changed should be an antipattern. This is basically polling in disguise: the whole architectural reason to use events is that they fire during state transitions. Not only is this wasteful, it’s unclear whether there is an actual benefit to it (compared to only firing the event when there is a state transition).

@LeaVerou LeaVerou changed the title New principle: Event listener invocation should be meaningful New principle: Events should only fire during actual state transitions Mar 25, 2024
@annevk
Copy link
Member

annevk commented Mar 26, 2024

That's correct. And the state transition and event are to be coupled together in a single task. You don't want to have one task updating the state and another firing the event.

@torgo torgo added this to the 2024-04-01-week milestone Mar 31, 2024
@LeaVerou
Copy link
Member Author

LeaVerou commented Apr 1, 2024

Discussed today in a breakout with @plinss:

There are two components to this:

  1. Naming guidance (change over update)
  2. Behavior guidance (events should not fire if no state transition has happened)

The first seems quite straightforward: change is definitely the de facto standard in the Web Platform right now, with timeupdate and compositionupdate being the outliers. Are there reasons these were not named timechange and compositionchange? If so, we should encode those reasons in the naming guidance. If not, we should list them as antipatterns.

The second also seems uncontroversial, but until the requesters reply in w3ctag/design-reviews#843 it's unclear if there has ever been an offender to this, in either an existing technology, a proposed one, or even a (popular) authorland one. If there is no example of anyone getting this wrong, I question the value of spending time writing it, though @plinss and I could not reach consensus about whether that means deprioritizing it or closing it altogether.

So to sum up:

  1. We should definitely encode the naming guidance in the naming section of the Design Principles
  2. Wrt the behavior guidance, let's leave this open for a bit and see if offenders emerge, and we can prioritize accordingly.

@annevk
Copy link
Member

annevk commented Apr 2, 2024

I think it's worth drawing a more explicit line between https://w3ctag.github.io/design-principles/#js-rtc and https://w3ctag.github.io/design-principles/#event-design. Even if there's no known offenders, there's quite a few people struggling with the event loop.

@torgo torgo modified the milestones: 2024-04-01-week, 2024-06-03-week Jun 2, 2024
@rhiaro rhiaro added the Status: Consensus to write We have TAG consensus about the principle but someone needs to write it (see "To Write" project) label Jun 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Consensus to write We have TAG consensus about the principle but someone needs to write it (see "To Write" project) Topic: Event Design
Projects
To Write
Awaiting triage
Development

No branches or pull requests

4 participants