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

How to removeEventListener? #75

Closed
esprehn opened this issue Sep 29, 2023 · 7 comments
Closed

How to removeEventListener? #75

esprehn opened this issue Sep 29, 2023 · 7 comments

Comments

@esprehn
Copy link

esprehn commented Sep 29, 2023

The word removeEventListener is never mentioned on the explainer or in the examples.

@domfarolino
Copy link
Collaborator

I guess it's not super explicitly enunciated, but the idea is that the teardown for a natively-constructed Observable returned via EventTarget#on() would remove the event listener. So if you passed an AbortSignal to subscribe(), when called one of of these EventTarget-observables, then when you abort the signal, it would teardown the Observable and remove the event listener, just like addEventListener() does today.

@esprehn
Copy link
Author

esprehn commented Oct 2, 2023

Does that mean if I don't pass an AbortSignal that there's no way to remove an event listener? That seems like a critical flaw compared to addEventListener where as long as you have the function you can always remove it.

for example if I do:

// imagine this is actually inside a component we instantiate a thousand times, not literally a loop.
for (let i = 0; i < 1000; ++i) {
  document.on('mousedown')
     .takeUntil(document.on('mouseup'))
     .subscribe({next: e => ...});
}

after I click how many event listeners remain on document?

@domfarolino
Copy link
Collaborator

Does that mean if I don't pass an AbortSignal that there's no way to remove an event listener?

No, so the real story is that when an observable subscription "closes" in any way (there are three ways: via AbortSignal, or the observable itself firing error() or complete() handlers), then the platform-internal "teardown" will be to remove the listener.

So with a normal subscription like element.on('click').subscribe({/*whoops, I forgot to pass in AbortSignal*/}) this observable will never "close" the subscription itself (nothing in C++ land will be prompted to call Subscriber#complete()), since you subscribed to an observable that was not defined to terminate (and you forgot to pass in your consumer-initiated termination mechanism).

But in your example, you're subscribing specifically to an observable that's designed to terminate, where the termination condition is defined by the operator you called. So when you call subscribe() above, internally here's what would happen:

  1. Install an event listener on document for mousedown, forwarding events outward to your next()
    • Set up a teardown to remove the event listener once the subscription closes
    • (So far, nothing here is specific to this operator in particular)
  2. Subscribe to the input document.on('mouseup') observable
    • Set up a teardown to cancel our "inner" subscription to this observable once the "outer" subscription closes
  3. Run the logic that's specific to the takeUntil() operator: This forwards mousedown events along, but calls complete() (thus closing the "outer" subscription to the observable returned by takeUntil()) when mouseup fires. As a part of closing that "outer" subscription, we run the two teardowns above.

after I click how many event listeners remain on document?

Given the above explanation, I believe the answer should be 0.

@esprehn
Copy link
Author

esprehn commented Oct 5, 2023

I see, thanks for the detailed explanation that's really helpful!

In rxjs subscribe returns a Subscription that has an unsubscribe callback, but that's been removed from this API. What was the reason for that? With addEventListener you can't lose the ability to unsubscribe as long as you keep the function reference around (which most folks do). It seems really easy with the on() API to subscribe deep down in a library and lose the ability to unsubscribe.

@Jamesernator
Copy link
Contributor

Jamesernator commented Oct 7, 2023

In rxjs subscribe returns a Subscription that has an unsubscribe callback, but that's been removed from this API. What was the reason for that?

This has been discussed in these issues:

The TLDR is that abort signals both are the existing mechanism for cancellation in browsers, and various problems like the synchronous firehose are directly resolvable by having the cancellation mechanism being available before the subscription is available.

It seems really easy with the on() API to subscribe deep down in a library and lose the ability to unsubscribe.

If a library didn't store the Subscription in a reference you'd lose the ability to unsubscribe anyway. There is no difference in any of the approaches in this regard, to be able to unsubscribe you need a reference to one of:

  • the callback, for .addEventListener
  • the abort controller for .addEventListener(..., { signal })
  • the subscription for Subscription based .subscribe(...)
  • the abort controller for the current .subscribe(...)

@benlesh
Copy link
Collaborator

benlesh commented Nov 29, 2023

When you're registering resources (like callbacks or subscriptions) with something, and you need to provide a means of removing the resource, there are a few patterns to follow:

  1. Return a means of removing the resource, (RxJS does this with subscribe(): Subscription, other APIs might return a removal function like subscribe(cb: Callback): UnsubscribeFunction, etc.
  2. Provide a separate unregistration function. This is what addEventListener and removeEventListener are. Or think of like the Observer pattern's Subject: addObserver/removeObserver, etc.
  3. Allow the consumer to pass in a token-based cancellation mechanism. This is AbortSignal, or in something like .NET, CancellationToken, etc.

Every single one of the above is just a different way to do the same thing. They all have advantages and disadvantages.

Using method 3 above, with AbortSignal has the most advantages for Observable because it allows the cancellation mechanism to be created before the subscription starts, when the subscription could emit values synchronously (as is required of anything that is going to model EventTarget). It's also nice because there's no need to keep the EventTarget instance itself on-hand to unregister the listener, like you would if you had to use removeEventListener. So to this point:

compared to addEventListener where as long as you have the function you can always remove it

...Sort of: You not only have to have a handle to your function, but you must also have a handle to the actual target as well, AND you have to know the "magic string" it was registered under. So you need 3 components: target.removeEventListener('type', func). With an AbortSignal, you only need to have a reference to the AbortController to unregister the listener.

chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue Nov 30, 2023
This CL implements "limited" and "leaky" EventTarget integration with the Observable API. See below for what "limited" and "leaky" mean.
Concretely, this involves introducing the `on()` method to the
EventTarget interface, so that all EventTargets can return Observables
that listen for events. This is the part that really makes Observables a
"better addEventListener()".

This is the first instance of a natively-constructed Observable, as
opposed to a JS-constructed Observable. This means the subscription
callback passed to the Observable constructor is not just a JS callback
function with user-defined code, but instead is a C++ delegate class,
called `SubscribeDelegate` which has its first concrete implementation
provided by EventTarget (in event_target.cc). The concrete
implementation of this interface that this CL introduces, adds an event
listener to the given EventTarget, upon subscription. The events are
forwarded to the Subscriber's `next()` method. This is what unlocks
more ergonomic event handling with the composable Observable primitive
and all of its (coming) operators.

1. The EventTarget integration is considered "limited" because we do not
support any of the `AddEventListenerOptions` yet, as of this CL. A
subsequent CL will add supported for a more restricted version of the
`AddEventListenerOptions`, called `ObservableEventListenerOptions`,
which does not include a `once` option, or an `AbortSignal`, since
Observable operators and subscription is responsible for managing those
aspects. Concretely, an `ObservableEventListenerOptions` will
resolve to an `AddEventListenerOptionsResolved` accordingly. See:
 - WICG/observable#66
 - WICG/observable#67
 - WICG/observable#65

2. The EventTarget integration is considered "leaky" as of this CL,
because there is currently no way to remove an event listener added by
an EventTarget-vended Observable. This will come in a subsequent CL,
which will pass the test that is currently failing in this CL. See
WICG/observable#75 for discussion about
tying the subscription termination to removing an event listener.
From a technical perspective, this is pretty easy — it involves adding
an abort algorithm to `Subscriber#signal` (which has already been wired
up properly by now!) that removes the given per-Subscription
`ObservableEventListener` NativeEventListener from the associated
EventTarget. That implementation has already been sketched out in
https://crrev.com/c/4262153 and the design doc. It will included in a
follow-up CL, to reduce the complexity of this one.

[email protected]

Bug: 1485981
Change-Id: Iafeddb0894b8eed2be1d95c181fc44d7650c0d47
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue Nov 30, 2023
This CL implements "limited" and "leaky" EventTarget integration with the Observable API. See below for what "limited" and "leaky" mean.
Concretely, this involves introducing the `on()` method to the
EventTarget interface, so that all EventTargets can return Observables
that listen for events. This is the part that really makes Observables a
"better addEventListener()".

This is the first instance of a natively-constructed Observable, as
opposed to a JS-constructed Observable. This means the subscription
callback passed to the Observable constructor is not just a JS callback
function with user-defined code, but instead is a C++ delegate class,
called `SubscribeDelegate` which has its first concrete implementation
provided by EventTarget (in event_target.cc). The concrete
implementation of this interface that this CL introduces, adds an event
listener to the given EventTarget, upon subscription. The events are
forwarded to the Subscriber's `next()` method. This is what unlocks
more ergonomic event handling with the composable Observable primitive
and all of its (coming) operators.

1. The EventTarget integration is considered "limited" because we do not
support any of the `AddEventListenerOptions` yet, as of this CL. A
subsequent CL will add supported for a more restricted version of the
`AddEventListenerOptions`, called `ObservableEventListenerOptions`,
which does not include a `once` option, or an `AbortSignal`, since
Observable operators and subscription is responsible for managing those
aspects. Concretely, an `ObservableEventListenerOptions` will
resolve to an `AddEventListenerOptionsResolved` accordingly. See:
 - WICG/observable#66
 - WICG/observable#67
 - WICG/observable#65

2. The EventTarget integration is considered "leaky" as of this CL,
because there is currently no way to remove an event listener added by
an EventTarget-vended Observable. This will come in a subsequent CL,
which will pass the test that is currently failing in this CL. See
WICG/observable#75 for discussion about
tying the subscription termination to removing an event listener.
From a technical perspective, this is pretty easy — it involves adding
an abort algorithm to `Subscriber#signal` (which has already been wired
up properly by now!) that removes the given per-Subscription
`ObservableEventListener` NativeEventListener from the associated
EventTarget. That implementation has already been sketched out in
https://crrev.com/c/4262153 and the design doc. It will included in a
follow-up CL, to reduce the complexity of this one.

[email protected]

Bug: 1485981
Change-Id: Iafeddb0894b8eed2be1d95c181fc44d7650c0d47
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue Nov 30, 2023
This CL implements "limited" and "leaky" EventTarget integration with the Observable API. See below for what "limited" and "leaky" mean.
Concretely, this involves introducing the `on()` method to the
EventTarget interface, so that all EventTargets can return Observables
that listen for events. This is the part that really makes Observables a
"better addEventListener()".

This is the first instance of a natively-constructed Observable, as
opposed to a JS-constructed Observable. This means the subscription
callback passed to the Observable constructor is not just a JS callback
function with user-defined code, but instead is a C++ delegate class,
called `SubscribeDelegate` which has its first concrete implementation
provided by EventTarget (in event_target.cc). The concrete
implementation of this interface that this CL introduces, adds an event
listener to the given EventTarget, upon subscription. The events are
forwarded to the Subscriber's `next()` method. This is what unlocks
more ergonomic event handling with the composable Observable primitive
and all of its (coming) operators.

1. The EventTarget integration is considered "limited" because we do not
support any of the `AddEventListenerOptions` yet, as of this CL. A
subsequent CL will add supported for a more restricted version of the
`AddEventListenerOptions`, called `ObservableEventListenerOptions`,
which does not include a `once` option, or an `AbortSignal`, since
Observable operators and subscription is responsible for managing those
aspects. Concretely, an `ObservableEventListenerOptions` will
resolve to an `AddEventListenerOptionsResolved` accordingly. See:
 - WICG/observable#66
 - WICG/observable#67
 - WICG/observable#65

2. The EventTarget integration is considered "leaky" as of this CL,
because there is currently no way to remove an event listener added by
an EventTarget-vended Observable. This will come in a subsequent CL,
which will pass the test that is currently failing in this CL. See
WICG/observable#75 for discussion about
tying the subscription termination to removing an event listener.
From a technical perspective, this is pretty easy — it involves adding
an abort algorithm to `Subscriber#signal` (which has already been wired
up properly by now!) that removes the given per-Subscription
`ObservableEventListener` NativeEventListener from the associated
EventTarget. That implementation has already been sketched out in
https://crrev.com/c/4262153 and the design doc. It will included in a
follow-up CL, to reduce the complexity of this one.

For WPTs:
Co-authored-by: [email protected]

[email protected]

Bug: 1485981
Change-Id: Iafeddb0894b8eed2be1d95c181fc44d7650c0d47
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue Nov 30, 2023
This CL implements "limited" and "leaky" EventTarget integration with the Observable API. See below for what "limited" and "leaky" mean.
Concretely, this involves introducing the `on()` method to the
EventTarget interface, so that all EventTargets can return Observables
that listen for events. This is the part that really makes Observables a
"better addEventListener()".

This is the first instance of a natively-constructed Observable, as
opposed to a JS-constructed Observable. This means the subscription
callback passed to the Observable constructor is not just a JS callback
function with user-defined code, but instead is a C++ delegate class,
called `SubscribeDelegate` which has its first concrete implementation
provided by EventTarget (in event_target.cc). The concrete
implementation of this interface that this CL introduces, adds an event
listener to the given EventTarget, upon subscription. The events are
forwarded to the Subscriber's `next()` method. This is what unlocks
more ergonomic event handling with the composable Observable primitive
and all of its (coming) operators.

1. The EventTarget integration is considered "limited" because we do not
support any of the `AddEventListenerOptions` yet, as of this CL. A
subsequent CL will add supported for a more restricted version of the
`AddEventListenerOptions`, called `ObservableEventListenerOptions`,
which does not include a `once` option, or an `AbortSignal`, since
Observable operators and subscription is responsible for managing those
aspects. Concretely, an `ObservableEventListenerOptions` will
resolve to an `AddEventListenerOptionsResolved` accordingly. See:
 - WICG/observable#66
 - WICG/observable#67
 - WICG/observable#65

2. The EventTarget integration is considered "leaky" as of this CL,
because there is currently no way to remove an event listener added by
an EventTarget-vended Observable. This will come in a subsequent CL,
which will pass the test that is currently failing in this CL. See
WICG/observable#75 for discussion about
tying the subscription termination to removing an event listener.
From a technical perspective, this is pretty easy — it involves adding
an abort algorithm to `Subscriber#signal` (which has already been wired
up properly by now!) that removes the given per-Subscription
`ObservableEventListener` NativeEventListener from the associated
EventTarget. That implementation has already been sketched out in
https://crrev.com/c/4262153 and the design doc. It will included in a
follow-up CL, to reduce the complexity of this one.

For WPTs:
Co-authored-by: [email protected]

[email protected]

Bug: 1485981
Change-Id: Iafeddb0894b8eed2be1d95c181fc44d7650c0d47
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue Dec 1, 2023
This CL implements "limited" and "leaky" EventTarget integration with the Observable API. See below for what "limited" and "leaky" mean.
Concretely, this involves introducing the `on()` method to the
EventTarget interface, so that all EventTargets can return Observables
that listen for events. This is the part that really makes Observables a
"better addEventListener()".

This is the first instance of a natively-constructed Observable, as
opposed to a JS-constructed Observable. This means the subscription
callback passed to the Observable constructor is not just a JS callback
function with user-defined code, but instead is a C++ delegate class,
called `SubscribeDelegate` which has its first concrete implementation
provided by EventTarget (in event_target.cc). The concrete
implementation of this interface that this CL introduces, adds an event
listener to the given EventTarget, upon subscription. The events are
forwarded to the Subscriber's `next()` method. This is what unlocks
more ergonomic event handling with the composable Observable primitive
and all of its (coming) operators.

1. The EventTarget integration is considered "limited" because we do not
support any of the `AddEventListenerOptions` yet, as of this CL. A
subsequent CL will add supported for a more restricted version of the
`AddEventListenerOptions`, called `ObservableEventListenerOptions`,
which does not include a `once` option, or an `AbortSignal`, since
Observable operators and subscription is responsible for managing those
aspects. Concretely, an `ObservableEventListenerOptions` will
resolve to an `AddEventListenerOptionsResolved` accordingly. See:
 - WICG/observable#66
 - WICG/observable#67
 - WICG/observable#65

2. The EventTarget integration is considered "leaky" as of this CL,
because there is currently no way to remove an event listener added by
an EventTarget-vended Observable. This will come in a subsequent CL,
which will pass the test that is currently failing in this CL. See
WICG/observable#75 for discussion about
tying the subscription termination to removing an event listener.
From a technical perspective, this is pretty easy — it involves adding
an abort algorithm to `Subscriber#signal` (which has already been wired
up properly by now!) that removes the given per-Subscription
`ObservableEventListener` NativeEventListener from the associated
EventTarget. That implementation has already been sketched out in
https://crrev.com/c/4262153 and the design doc. It will included in a
follow-up CL, to reduce the complexity of this one.

For WPTs:
Co-authored-by: [email protected]

[email protected]

Bug: 1485981
Change-Id: Iafeddb0894b8eed2be1d95c181fc44d7650c0d47
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue Dec 5, 2023
This CL implements "limited" and "leaky" EventTarget integration with the Observable API. See below for what "limited" and "leaky" mean.
Concretely, this involves introducing the `on()` method to the
EventTarget interface, so that all EventTargets can return Observables
that listen for events. This is the part that really makes Observables a
"better addEventListener()".

This is the first instance of a natively-constructed Observable, as
opposed to a JS-constructed Observable. This means the subscription
callback passed to the Observable constructor is not just a JS callback
function with user-defined code, but instead is a C++ delegate class,
called `SubscribeDelegate` which has its first concrete implementation
provided by EventTarget (in event_target.cc). The concrete
implementation of this interface that this CL introduces, adds an event
listener to the given EventTarget, upon subscription. The events are
forwarded to the Subscriber's `next()` method. This is what unlocks
more ergonomic event handling with the composable Observable primitive
and all of its (coming) operators.

1. The EventTarget integration is considered "limited" because we do not
support any of the `AddEventListenerOptions` yet, as of this CL. A
subsequent CL will add supported for a more restricted version of the
`AddEventListenerOptions`, called `ObservableEventListenerOptions`,
which does not include a `once` option, or an `AbortSignal`, since
Observable operators and subscription is responsible for managing those
aspects. Concretely, an `ObservableEventListenerOptions` will
resolve to an `AddEventListenerOptionsResolved` accordingly. See:
 - WICG/observable#66
 - WICG/observable#67
 - WICG/observable#65

2. The EventTarget integration is considered "leaky" as of this CL,
because there is currently no way to remove an event listener added by
an EventTarget-vended Observable. This will come in a subsequent CL,
which will pass the test that is currently failing in this CL. See
WICG/observable#75 for discussion about
tying the subscription termination to removing an event listener.
From a technical perspective, this is pretty easy — it involves adding
an abort algorithm to `Subscriber#signal` (which has already been wired
up properly by now!) that removes the given per-Subscription
`ObservableEventListener` NativeEventListener from the associated
EventTarget. That implementation has already been sketched out in
https://crrev.com/c/4262153 and the design doc. It will included in a
follow-up CL, to reduce the complexity of this one.

For WPTs:
Co-authored-by: [email protected]

[email protected]

Bug: 1485981
Change-Id: Iafeddb0894b8eed2be1d95c181fc44d7650c0d47
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue Dec 5, 2023
This CL implements "limited" and "leaky" EventTarget integration with the Observable API. See below for what "limited" and "leaky" mean.
Concretely, this involves introducing the `on()` method to the
EventTarget interface, so that all EventTargets can return Observables
that listen for events. This is the part that really makes Observables a
"better addEventListener()".

This is the first instance of a natively-constructed Observable, as
opposed to a JS-constructed Observable. This means the subscription
callback passed to the Observable constructor is not just a JS callback
function with user-defined code, but instead is a C++ delegate class,
called `SubscribeDelegate` which has its first concrete implementation
provided by EventTarget (in event_target.cc). The concrete
implementation of this interface that this CL introduces, adds an event
listener to the given EventTarget, upon subscription. The events are
forwarded to the Subscriber's `next()` method. This is what unlocks
more ergonomic event handling with the composable Observable primitive
and all of its (coming) operators.

1. The EventTarget integration is considered "limited" because we do not
support any of the `AddEventListenerOptions` yet, as of this CL. A
subsequent CL will add supported for a more restricted version of the
`AddEventListenerOptions`, called `ObservableEventListenerOptions`,
which does not include a `once` option, or an `AbortSignal`, since
Observable operators and subscription is responsible for managing those
aspects. Concretely, an `ObservableEventListenerOptions` will
resolve to an `AddEventListenerOptionsResolved` accordingly. See:
 - WICG/observable#66
 - WICG/observable#67
 - WICG/observable#65

2. The EventTarget integration is considered "leaky" as of this CL,
because there is currently no way to remove an event listener added by
an EventTarget-vended Observable. This will come in a subsequent CL,
which will pass the test that is currently failing in this CL. See
WICG/observable#75 for discussion about
tying the subscription termination to removing an event listener.
From a technical perspective, this is pretty easy — it involves adding
an abort algorithm to `Subscriber#signal` (which has already been wired
up properly by now!) that removes the given per-Subscription
`ObservableEventListener` NativeEventListener from the associated
EventTarget. That implementation has already been sketched out in
https://crrev.com/c/4262153 and the design doc. It will included in a
follow-up CL, to reduce the complexity of this one.

For WPTs:
Co-authored-by: [email protected]

[email protected]

Bug: 1485981
Change-Id: Iafeddb0894b8eed2be1d95c181fc44d7650c0d47
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue Dec 5, 2023
This CL implements "limited" and "leaky" EventTarget integration with the Observable API. See below for what "limited" and "leaky" mean.
Concretely, this involves introducing the `on()` method to the
EventTarget interface, so that all EventTargets can return Observables
that listen for events. This is the part that really makes Observables a
"better addEventListener()".

This is the first instance of a natively-constructed Observable, as
opposed to a JS-constructed Observable. This means the subscription
callback passed to the Observable constructor is not just a JS callback
function with user-defined code, but instead is a C++ delegate class,
called `SubscribeDelegate` which has its first concrete implementation
provided by EventTarget (in event_target.cc). The concrete
implementation of this interface that this CL introduces, adds an event
listener to the given EventTarget, upon subscription. The events are
forwarded to the Subscriber's `next()` method. This is what unlocks
more ergonomic event handling with the composable Observable primitive
and all of its (coming) operators.

1. The EventTarget integration is considered "limited" because we do not
support any of the `AddEventListenerOptions` yet, as of this CL. A
subsequent CL will add supported for a more restricted version of the
`AddEventListenerOptions`, called `ObservableEventListenerOptions`,
which does not include a `once` option, or an `AbortSignal`, since
Observable operators and subscription is responsible for managing those
aspects. Concretely, an `ObservableEventListenerOptions` will
resolve to an `AddEventListenerOptionsResolved` accordingly. See:
 - WICG/observable#66
 - WICG/observable#67
 - WICG/observable#65

2. The EventTarget integration is considered "leaky" as of this CL,
because there is currently no way to remove an event listener added by
an EventTarget-vended Observable. This will come in a subsequent CL,
which will pass the test that is currently failing in this CL. See
WICG/observable#75 for discussion about
tying the subscription termination to removing an event listener.
From a technical perspective, this is pretty easy — it involves adding
an abort algorithm to `Subscriber#signal` (which has already been wired
up properly by now!) that removes the given per-Subscription
`ObservableEventListener` NativeEventListener from the associated
EventTarget. That implementation has already been sketched out in
https://crrev.com/c/4262153 and the design doc. It will included in a
follow-up CL, to reduce the complexity of this one.

For WPTs:
Co-authored-by: [email protected]

[email protected]

Bug: 1485981
Change-Id: Iafeddb0894b8eed2be1d95c181fc44d7650c0d47
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue Dec 7, 2023
This CL implements "limited" and "leaky" EventTarget integration with
the Observable API. See below for what "limited" and "leaky" mean.
Concretely, this involves introducing the `on()` method to the
EventTarget interface, so that all EventTargets can return Observables
that listen for events. This is the part that really makes Observables a
"better addEventListener()".

This is the first instance of a natively-constructed Observable, as
opposed to a JS-constructed Observable. This means the subscription
callback passed to the Observable constructor is not just a JS callback
function with user-defined code, but instead is a C++ delegate class,
called `SubscribeDelegate` which has its first concrete implementation
provided by EventTarget (in event_target.cc). The concrete
implementation of this interface that this CL introduces, adds an event
listener to the given EventTarget, upon subscription. The events are
forwarded to the Subscriber's `next()` method. This is what unlocks
more ergonomic event handling with the composable Observable primitive
and all of its (coming) operators.

1. The EventTarget integration is considered "limited" because we do not
support any of the `AddEventListenerOptions` yet, as of this CL. A
subsequent CL will add support for a more restricted version of the
`AddEventListenerOptions`, called `ObservableEventListenerOptions`,
which does not include a `once` option, or an `AbortSignal`, since
Observable operators and subscription is responsible for managing those
aspects. Concretely, an `ObservableEventListenerOptions` will
resolve to an `AddEventListenerOptionsResolved` accordingly. See:
 - WICG/observable#66
 - WICG/observable#67
 - WICG/observable#65

2. The EventTarget integration is considered "leaky" as of this CL,
because there is currently no way to remove an event listener added by
an EventTarget-vended Observable. This will come in a subsequent CL,
which will pass the test that is currently failing in this CL. See
WICG/observable#75 for discussion about
tying the subscription termination to removing an event listener.
From a technical perspective, this is pretty easy — it involves adding
an abort algorithm to `Subscriber#signal` (which has already been wired
up properly by now!) that removes the given per-Subscription
`ObservableEventListener` NativeEventListener from the associated
EventTarget. That implementation has already been sketched out in
https://crrev.com/c/4262153 and the design doc. It will included in a
follow-up CL, to reduce the complexity of this one.

For WPTs:
Co-authored-by: [email protected]

[email protected]

Bug: 1485981
Change-Id: Iafeddb0894b8eed2be1d95c181fc44d7650c0d47
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue Dec 7, 2023
This CL implements "limited" and "leaky" EventTarget integration with
the Observable API. See below for what "limited" and "leaky" mean.
Concretely, this involves introducing the `on()` method to the
EventTarget interface, so that all EventTargets can return Observables
that listen for events. This is the part that really makes Observables a
"better addEventListener()".

This is the first instance of a natively-constructed Observable, as
opposed to a JS-constructed Observable. This means the subscription
callback passed to the Observable constructor is not just a JS callback
function with user-defined code, but instead is a C++ delegate class,
called `SubscribeDelegate` which has its first concrete implementation
provided by EventTarget (in event_target.cc). The concrete
implementation of this interface that this CL introduces, adds an event
listener to the given EventTarget, upon subscription. The events are
forwarded to the Subscriber's `next()` method. This is what unlocks
more ergonomic event handling with the composable Observable primitive
and all of its (coming) operators.

1. The EventTarget integration is considered "limited" because we do not
support any of the `AddEventListenerOptions` yet, as of this CL. A
subsequent CL will add support for a more restricted version of the
`AddEventListenerOptions`, called `ObservableEventListenerOptions`,
which does not include a `once` option, or an `AbortSignal`, since
Observable operators and subscription is responsible for managing those
aspects. Concretely, an `ObservableEventListenerOptions` will
resolve to an `AddEventListenerOptionsResolved` accordingly. See:
 - WICG/observable#66
 - WICG/observable#67
 - WICG/observable#65

2. The EventTarget integration is considered "leaky" as of this CL,
because there is currently no way to remove an event listener added by
an EventTarget-vended Observable. This will come in a subsequent CL,
which will pass the test that is currently failing in this CL. See
WICG/observable#75 for discussion about
tying the subscription termination to removing an event listener.
From a technical perspective, this is pretty easy — it involves adding
an abort algorithm to `Subscriber#signal` (which has already been wired
up properly by now!) that removes the given per-Subscription
`ObservableEventListener` NativeEventListener from the associated
EventTarget. That implementation has already been sketched out in
https://crrev.com/c/4262153 and the design doc. It will included in a
follow-up CL, to reduce the complexity of this one.

For WPTs:
Co-authored-by: [email protected]

[email protected]

Bug: 1485981
Change-Id: Iafeddb0894b8eed2be1d95c181fc44d7650c0d47
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue Dec 7, 2023
This CL implements "limited" and "leaky" EventTarget integration with
the Observable API. See below for what "limited" and "leaky" mean.
Concretely, this involves introducing the `on()` method to the
EventTarget interface, so that all EventTargets can return Observables
that listen for events. This is the part that really makes Observables a
"better addEventListener()".

This is the first instance of a natively-constructed Observable, as
opposed to a JS-constructed Observable. This means the subscription
callback passed to the Observable constructor is not just a JS callback
function with user-defined code, but instead is a C++ delegate class,
called `SubscribeDelegate` which has its first concrete implementation
provided by EventTarget (in event_target.cc). The concrete
implementation of this interface that this CL introduces, adds an event
listener to the given EventTarget, upon subscription. The events are
forwarded to the Subscriber's `next()` method. This is what unlocks
more ergonomic event handling with the composable Observable primitive
and all of its (coming) operators.

1. The EventTarget integration is considered "limited" because we do not
support any of the `AddEventListenerOptions` yet, as of this CL. A
subsequent CL will add support for a more restricted version of the
`AddEventListenerOptions`, called `ObservableEventListenerOptions`,
which does not include a `once` option, or an `AbortSignal`, since
Observable operators and subscription is responsible for managing those
aspects. Concretely, an `ObservableEventListenerOptions` will
resolve to an `AddEventListenerOptionsResolved` accordingly. See:
 - WICG/observable#66
 - WICG/observable#67
 - WICG/observable#65

2. The EventTarget integration is considered "leaky" as of this CL,
because there is currently no way to remove an event listener added by
an EventTarget-vended Observable. This will come in a subsequent CL,
which will pass the test that is currently failing in this CL. See
WICG/observable#75 for discussion about
tying the subscription termination to removing an event listener.
From a technical perspective, this is pretty easy — it involves adding
an abort algorithm to `Subscriber#signal` (which has already been wired
up properly by now!) that removes the given per-Subscription
`ObservableEventListener` NativeEventListener from the associated
EventTarget. That implementation has already been sketched out in
https://crrev.com/c/4262153 and the design doc. It will included in a
follow-up CL, to reduce the complexity of this one.

For WPTs:
Co-authored-by: [email protected]

[email protected]

Bug: 1485981
Change-Id: Iafeddb0894b8eed2be1d95c181fc44d7650c0d47
aarongable pushed a commit to chromium/chromium that referenced this issue Dec 14, 2023
This CL implements "limited" and "leaky" EventTarget integration with
the Observable API. See below for what "limited" and "leaky" mean.
Concretely, this involves introducing the `on()` method to the
EventTarget interface, so that all EventTargets can return Observables
that listen for events. This is the part that really makes Observables a
"better addEventListener()".

This is the first instance of a natively-constructed Observable, as
opposed to a JS-constructed Observable. This means the subscription
callback passed to the Observable constructor is not just a JS callback
function with user-defined code, but instead is a C++ delegate class,
called `SubscribeDelegate` which has its first concrete implementation
provided by EventTarget (in event_target.cc). The concrete
implementation of this interface that this CL introduces, adds an event
listener to the given EventTarget, upon subscription. The events are
forwarded to the Subscriber's `next()` method. This is what unlocks
more ergonomic event handling with the composable Observable primitive
and all of its (coming) operators.

1. The EventTarget integration is considered "limited" because we do not
support any of the `AddEventListenerOptions` yet, as of this CL. A
subsequent CL will add support for a more restricted version of the
`AddEventListenerOptions`, called `ObservableEventListenerOptions`,
which does not include a `once` option, or an `AbortSignal`, since
Observable operators and subscription is responsible for managing those
aspects. Concretely, an `ObservableEventListenerOptions` will
resolve to an `AddEventListenerOptionsResolved` accordingly. See:
 - WICG/observable#66
 - WICG/observable#67
 - WICG/observable#65

2. The EventTarget integration is considered "leaky" as of this CL,
because there is currently no way to remove an event listener added by
an EventTarget-vended Observable. This will come in a subsequent CL,
which will pass the test that is currently failing in this CL. See
WICG/observable#75 for discussion about
tying the subscription termination to removing an event listener.
From a technical perspective, this is pretty easy — it involves adding
an abort algorithm to `Subscriber#signal` (which has already been wired
up properly by now!) that removes the given per-Subscription
`ObservableEventListener` NativeEventListener from the associated
EventTarget. That implementation has already been sketched out in
https://crrev.com/c/4262153 and the design doc. It will included in a
follow-up CL, to reduce the complexity of this one.

For WPTs:
Co-authored-by: [email protected]

[email protected]

Bug: 1485981
Change-Id: Iafeddb0894b8eed2be1d95c181fc44d7650c0d47
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5073394
Reviewed-by: Mason Freed <[email protected]>
Commit-Queue: Dominic Farolino <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1237501}
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue Dec 14, 2023
This CL implements "limited" and "leaky" EventTarget integration with
the Observable API. See below for what "limited" and "leaky" mean.
Concretely, this involves introducing the `on()` method to the
EventTarget interface, so that all EventTargets can return Observables
that listen for events. This is the part that really makes Observables a
"better addEventListener()".

This is the first instance of a natively-constructed Observable, as
opposed to a JS-constructed Observable. This means the subscription
callback passed to the Observable constructor is not just a JS callback
function with user-defined code, but instead is a C++ delegate class,
called `SubscribeDelegate` which has its first concrete implementation
provided by EventTarget (in event_target.cc). The concrete
implementation of this interface that this CL introduces, adds an event
listener to the given EventTarget, upon subscription. The events are
forwarded to the Subscriber's `next()` method. This is what unlocks
more ergonomic event handling with the composable Observable primitive
and all of its (coming) operators.

1. The EventTarget integration is considered "limited" because we do not
support any of the `AddEventListenerOptions` yet, as of this CL. A
subsequent CL will add support for a more restricted version of the
`AddEventListenerOptions`, called `ObservableEventListenerOptions`,
which does not include a `once` option, or an `AbortSignal`, since
Observable operators and subscription is responsible for managing those
aspects. Concretely, an `ObservableEventListenerOptions` will
resolve to an `AddEventListenerOptionsResolved` accordingly. See:
 - WICG/observable#66
 - WICG/observable#67
 - WICG/observable#65

2. The EventTarget integration is considered "leaky" as of this CL,
because there is currently no way to remove an event listener added by
an EventTarget-vended Observable. This will come in a subsequent CL,
which will pass the test that is currently failing in this CL. See
WICG/observable#75 for discussion about
tying the subscription termination to removing an event listener.
From a technical perspective, this is pretty easy — it involves adding
an abort algorithm to `Subscriber#signal` (which has already been wired
up properly by now!) that removes the given per-Subscription
`ObservableEventListener` NativeEventListener from the associated
EventTarget. That implementation has already been sketched out in
https://crrev.com/c/4262153 and the design doc. It will included in a
follow-up CL, to reduce the complexity of this one.

For WPTs:
Co-authored-by: [email protected]

[email protected]

Bug: 1485981
Change-Id: Iafeddb0894b8eed2be1d95c181fc44d7650c0d47
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5073394
Reviewed-by: Mason Freed <[email protected]>
Commit-Queue: Dominic Farolino <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1237501}
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue Dec 14, 2023
This CL implements "limited" and "leaky" EventTarget integration with
the Observable API. See below for what "limited" and "leaky" mean.
Concretely, this involves introducing the `on()` method to the
EventTarget interface, so that all EventTargets can return Observables
that listen for events. This is the part that really makes Observables a
"better addEventListener()".

This is the first instance of a natively-constructed Observable, as
opposed to a JS-constructed Observable. This means the subscription
callback passed to the Observable constructor is not just a JS callback
function with user-defined code, but instead is a C++ delegate class,
called `SubscribeDelegate` which has its first concrete implementation
provided by EventTarget (in event_target.cc). The concrete
implementation of this interface that this CL introduces, adds an event
listener to the given EventTarget, upon subscription. The events are
forwarded to the Subscriber's `next()` method. This is what unlocks
more ergonomic event handling with the composable Observable primitive
and all of its (coming) operators.

1. The EventTarget integration is considered "limited" because we do not
support any of the `AddEventListenerOptions` yet, as of this CL. A
subsequent CL will add support for a more restricted version of the
`AddEventListenerOptions`, called `ObservableEventListenerOptions`,
which does not include a `once` option, or an `AbortSignal`, since
Observable operators and subscription is responsible for managing those
aspects. Concretely, an `ObservableEventListenerOptions` will
resolve to an `AddEventListenerOptionsResolved` accordingly. See:
 - WICG/observable#66
 - WICG/observable#67
 - WICG/observable#65

2. The EventTarget integration is considered "leaky" as of this CL,
because there is currently no way to remove an event listener added by
an EventTarget-vended Observable. This will come in a subsequent CL,
which will pass the test that is currently failing in this CL. See
WICG/observable#75 for discussion about
tying the subscription termination to removing an event listener.
From a technical perspective, this is pretty easy — it involves adding
an abort algorithm to `Subscriber#signal` (which has already been wired
up properly by now!) that removes the given per-Subscription
`ObservableEventListener` NativeEventListener from the associated
EventTarget. That implementation has already been sketched out in
https://crrev.com/c/4262153 and the design doc. It will included in a
follow-up CL, to reduce the complexity of this one.

For WPTs:
Co-authored-by: [email protected]

[email protected]

Bug: 1485981
Change-Id: Iafeddb0894b8eed2be1d95c181fc44d7650c0d47
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5073394
Reviewed-by: Mason Freed <[email protected]>
Commit-Queue: Dominic Farolino <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1237501}
moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this issue Dec 15, 2023
…1/N, a=testonly

Automatic update from web-platform-tests
DOM: Observable EventTarget integration 1/N

This CL implements "limited" and "leaky" EventTarget integration with
the Observable API. See below for what "limited" and "leaky" mean.
Concretely, this involves introducing the `on()` method to the
EventTarget interface, so that all EventTargets can return Observables
that listen for events. This is the part that really makes Observables a
"better addEventListener()".

This is the first instance of a natively-constructed Observable, as
opposed to a JS-constructed Observable. This means the subscription
callback passed to the Observable constructor is not just a JS callback
function with user-defined code, but instead is a C++ delegate class,
called `SubscribeDelegate` which has its first concrete implementation
provided by EventTarget (in event_target.cc). The concrete
implementation of this interface that this CL introduces, adds an event
listener to the given EventTarget, upon subscription. The events are
forwarded to the Subscriber's `next()` method. This is what unlocks
more ergonomic event handling with the composable Observable primitive
and all of its (coming) operators.

1. The EventTarget integration is considered "limited" because we do not
support any of the `AddEventListenerOptions` yet, as of this CL. A
subsequent CL will add support for a more restricted version of the
`AddEventListenerOptions`, called `ObservableEventListenerOptions`,
which does not include a `once` option, or an `AbortSignal`, since
Observable operators and subscription is responsible for managing those
aspects. Concretely, an `ObservableEventListenerOptions` will
resolve to an `AddEventListenerOptionsResolved` accordingly. See:
 - WICG/observable#66
 - WICG/observable#67
 - WICG/observable#65

2. The EventTarget integration is considered "leaky" as of this CL,
because there is currently no way to remove an event listener added by
an EventTarget-vended Observable. This will come in a subsequent CL,
which will pass the test that is currently failing in this CL. See
WICG/observable#75 for discussion about
tying the subscription termination to removing an event listener.
From a technical perspective, this is pretty easy — it involves adding
an abort algorithm to `Subscriber#signal` (which has already been wired
up properly by now!) that removes the given per-Subscription
`ObservableEventListener` NativeEventListener from the associated
EventTarget. That implementation has already been sketched out in
https://crrev.com/c/4262153 and the design doc. It will included in a
follow-up CL, to reduce the complexity of this one.

For WPTs:
Co-authored-by: [email protected]

[email protected]

Bug: 1485981
Change-Id: Iafeddb0894b8eed2be1d95c181fc44d7650c0d47
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5073394
Reviewed-by: Mason Freed <[email protected]>
Commit-Queue: Dominic Farolino <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1237501}

--

wpt-commits: aeeea4221bce5c44edeb8adad0296bbd68a4af71
wpt-pr: 43455
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified-and-comments-removed that referenced this issue Dec 16, 2023
…1/N, a=testonly

Automatic update from web-platform-tests
DOM: Observable EventTarget integration 1/N

This CL implements "limited" and "leaky" EventTarget integration with
the Observable API. See below for what "limited" and "leaky" mean.
Concretely, this involves introducing the `on()` method to the
EventTarget interface, so that all EventTargets can return Observables
that listen for events. This is the part that really makes Observables a
"better addEventListener()".

This is the first instance of a natively-constructed Observable, as
opposed to a JS-constructed Observable. This means the subscription
callback passed to the Observable constructor is not just a JS callback
function with user-defined code, but instead is a C++ delegate class,
called `SubscribeDelegate` which has its first concrete implementation
provided by EventTarget (in event_target.cc). The concrete
implementation of this interface that this CL introduces, adds an event
listener to the given EventTarget, upon subscription. The events are
forwarded to the Subscriber's `next()` method. This is what unlocks
more ergonomic event handling with the composable Observable primitive
and all of its (coming) operators.

1. The EventTarget integration is considered "limited" because we do not
support any of the `AddEventListenerOptions` yet, as of this CL. A
subsequent CL will add support for a more restricted version of the
`AddEventListenerOptions`, called `ObservableEventListenerOptions`,
which does not include a `once` option, or an `AbortSignal`, since
Observable operators and subscription is responsible for managing those
aspects. Concretely, an `ObservableEventListenerOptions` will
resolve to an `AddEventListenerOptionsResolved` accordingly. See:
 - WICG/observable#66
 - WICG/observable#67
 - WICG/observable#65

2. The EventTarget integration is considered "leaky" as of this CL,
because there is currently no way to remove an event listener added by
an EventTarget-vended Observable. This will come in a subsequent CL,
which will pass the test that is currently failing in this CL. See
WICG/observable#75 for discussion about
tying the subscription termination to removing an event listener.
From a technical perspective, this is pretty easy — it involves adding
an abort algorithm to `Subscriber#signal` (which has already been wired
up properly by now!) that removes the given per-Subscription
`ObservableEventListener` NativeEventListener from the associated
EventTarget. That implementation has already been sketched out in
https://crrev.com/c/4262153 and the design doc. It will included in a
follow-up CL, to reduce the complexity of this one.

For WPTs:
Co-authored-by: benbenlesh.com

R=masonfchromium.org

Bug: 1485981
Change-Id: Iafeddb0894b8eed2be1d95c181fc44d7650c0d47
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5073394
Reviewed-by: Mason Freed <masonfchromium.org>
Commit-Queue: Dominic Farolino <domchromium.org>
Cr-Commit-Position: refs/heads/main{#1237501}

--

wpt-commits: aeeea4221bce5c44edeb8adad0296bbd68a4af71
wpt-pr: 43455

UltraBlame original commit: 152cc51982905b4522338a38f9542e691a6a93e3
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified that referenced this issue Dec 16, 2023
…1/N, a=testonly

Automatic update from web-platform-tests
DOM: Observable EventTarget integration 1/N

This CL implements "limited" and "leaky" EventTarget integration with
the Observable API. See below for what "limited" and "leaky" mean.
Concretely, this involves introducing the `on()` method to the
EventTarget interface, so that all EventTargets can return Observables
that listen for events. This is the part that really makes Observables a
"better addEventListener()".

This is the first instance of a natively-constructed Observable, as
opposed to a JS-constructed Observable. This means the subscription
callback passed to the Observable constructor is not just a JS callback
function with user-defined code, but instead is a C++ delegate class,
called `SubscribeDelegate` which has its first concrete implementation
provided by EventTarget (in event_target.cc). The concrete
implementation of this interface that this CL introduces, adds an event
listener to the given EventTarget, upon subscription. The events are
forwarded to the Subscriber's `next()` method. This is what unlocks
more ergonomic event handling with the composable Observable primitive
and all of its (coming) operators.

1. The EventTarget integration is considered "limited" because we do not
support any of the `AddEventListenerOptions` yet, as of this CL. A
subsequent CL will add support for a more restricted version of the
`AddEventListenerOptions`, called `ObservableEventListenerOptions`,
which does not include a `once` option, or an `AbortSignal`, since
Observable operators and subscription is responsible for managing those
aspects. Concretely, an `ObservableEventListenerOptions` will
resolve to an `AddEventListenerOptionsResolved` accordingly. See:
 - WICG/observable#66
 - WICG/observable#67
 - WICG/observable#65

2. The EventTarget integration is considered "leaky" as of this CL,
because there is currently no way to remove an event listener added by
an EventTarget-vended Observable. This will come in a subsequent CL,
which will pass the test that is currently failing in this CL. See
WICG/observable#75 for discussion about
tying the subscription termination to removing an event listener.
From a technical perspective, this is pretty easy — it involves adding
an abort algorithm to `Subscriber#signal` (which has already been wired
up properly by now!) that removes the given per-Subscription
`ObservableEventListener` NativeEventListener from the associated
EventTarget. That implementation has already been sketched out in
https://crrev.com/c/4262153 and the design doc. It will included in a
follow-up CL, to reduce the complexity of this one.

For WPTs:
Co-authored-by: benbenlesh.com

R=masonfchromium.org

Bug: 1485981
Change-Id: Iafeddb0894b8eed2be1d95c181fc44d7650c0d47
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5073394
Reviewed-by: Mason Freed <masonfchromium.org>
Commit-Queue: Dominic Farolino <domchromium.org>
Cr-Commit-Position: refs/heads/main{#1237501}

--

wpt-commits: aeeea4221bce5c44edeb8adad0296bbd68a4af71
wpt-pr: 43455

UltraBlame original commit: 152cc51982905b4522338a38f9542e691a6a93e3
gecko-dev-updater pushed a commit to marco-c/gecko-dev-comments-removed that referenced this issue Dec 16, 2023
…1/N, a=testonly

Automatic update from web-platform-tests
DOM: Observable EventTarget integration 1/N

This CL implements "limited" and "leaky" EventTarget integration with
the Observable API. See below for what "limited" and "leaky" mean.
Concretely, this involves introducing the `on()` method to the
EventTarget interface, so that all EventTargets can return Observables
that listen for events. This is the part that really makes Observables a
"better addEventListener()".

This is the first instance of a natively-constructed Observable, as
opposed to a JS-constructed Observable. This means the subscription
callback passed to the Observable constructor is not just a JS callback
function with user-defined code, but instead is a C++ delegate class,
called `SubscribeDelegate` which has its first concrete implementation
provided by EventTarget (in event_target.cc). The concrete
implementation of this interface that this CL introduces, adds an event
listener to the given EventTarget, upon subscription. The events are
forwarded to the Subscriber's `next()` method. This is what unlocks
more ergonomic event handling with the composable Observable primitive
and all of its (coming) operators.

1. The EventTarget integration is considered "limited" because we do not
support any of the `AddEventListenerOptions` yet, as of this CL. A
subsequent CL will add support for a more restricted version of the
`AddEventListenerOptions`, called `ObservableEventListenerOptions`,
which does not include a `once` option, or an `AbortSignal`, since
Observable operators and subscription is responsible for managing those
aspects. Concretely, an `ObservableEventListenerOptions` will
resolve to an `AddEventListenerOptionsResolved` accordingly. See:
 - WICG/observable#66
 - WICG/observable#67
 - WICG/observable#65

2. The EventTarget integration is considered "leaky" as of this CL,
because there is currently no way to remove an event listener added by
an EventTarget-vended Observable. This will come in a subsequent CL,
which will pass the test that is currently failing in this CL. See
WICG/observable#75 for discussion about
tying the subscription termination to removing an event listener.
From a technical perspective, this is pretty easy — it involves adding
an abort algorithm to `Subscriber#signal` (which has already been wired
up properly by now!) that removes the given per-Subscription
`ObservableEventListener` NativeEventListener from the associated
EventTarget. That implementation has already been sketched out in
https://crrev.com/c/4262153 and the design doc. It will included in a
follow-up CL, to reduce the complexity of this one.

For WPTs:
Co-authored-by: benbenlesh.com

R=masonfchromium.org

Bug: 1485981
Change-Id: Iafeddb0894b8eed2be1d95c181fc44d7650c0d47
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5073394
Reviewed-by: Mason Freed <masonfchromium.org>
Commit-Queue: Dominic Farolino <domchromium.org>
Cr-Commit-Position: refs/heads/main{#1237501}

--

wpt-commits: aeeea4221bce5c44edeb8adad0296bbd68a4af71
wpt-pr: 43455

UltraBlame original commit: 152cc51982905b4522338a38f9542e691a6a93e3
aosmond pushed a commit to aosmond/gecko that referenced this issue Dec 16, 2023
…1/N, a=testonly

Automatic update from web-platform-tests
DOM: Observable EventTarget integration 1/N

This CL implements "limited" and "leaky" EventTarget integration with
the Observable API. See below for what "limited" and "leaky" mean.
Concretely, this involves introducing the `on()` method to the
EventTarget interface, so that all EventTargets can return Observables
that listen for events. This is the part that really makes Observables a
"better addEventListener()".

This is the first instance of a natively-constructed Observable, as
opposed to a JS-constructed Observable. This means the subscription
callback passed to the Observable constructor is not just a JS callback
function with user-defined code, but instead is a C++ delegate class,
called `SubscribeDelegate` which has its first concrete implementation
provided by EventTarget (in event_target.cc). The concrete
implementation of this interface that this CL introduces, adds an event
listener to the given EventTarget, upon subscription. The events are
forwarded to the Subscriber's `next()` method. This is what unlocks
more ergonomic event handling with the composable Observable primitive
and all of its (coming) operators.

1. The EventTarget integration is considered "limited" because we do not
support any of the `AddEventListenerOptions` yet, as of this CL. A
subsequent CL will add support for a more restricted version of the
`AddEventListenerOptions`, called `ObservableEventListenerOptions`,
which does not include a `once` option, or an `AbortSignal`, since
Observable operators and subscription is responsible for managing those
aspects. Concretely, an `ObservableEventListenerOptions` will
resolve to an `AddEventListenerOptionsResolved` accordingly. See:
 - WICG/observable#66
 - WICG/observable#67
 - WICG/observable#65

2. The EventTarget integration is considered "leaky" as of this CL,
because there is currently no way to remove an event listener added by
an EventTarget-vended Observable. This will come in a subsequent CL,
which will pass the test that is currently failing in this CL. See
WICG/observable#75 for discussion about
tying the subscription termination to removing an event listener.
From a technical perspective, this is pretty easy — it involves adding
an abort algorithm to `Subscriber#signal` (which has already been wired
up properly by now!) that removes the given per-Subscription
`ObservableEventListener` NativeEventListener from the associated
EventTarget. That implementation has already been sketched out in
https://crrev.com/c/4262153 and the design doc. It will included in a
follow-up CL, to reduce the complexity of this one.

For WPTs:
Co-authored-by: [email protected]

[email protected]

Bug: 1485981
Change-Id: Iafeddb0894b8eed2be1d95c181fc44d7650c0d47
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5073394
Reviewed-by: Mason Freed <[email protected]>
Commit-Queue: Dominic Farolino <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1237501}

--

wpt-commits: aeeea4221bce5c44edeb8adad0296bbd68a4af71
wpt-pr: 43455
@domfarolino
Copy link
Collaborator

I think the concerns originally raised in this issue have been suitably resolved with the design of the Observable API (see comments #75 (comment) and #75 (comment)), and I think all questions have been answered up to this point. So I'm going to close this issue, but feel free to re-open to keep the discussion going if you feel the need to!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants