Skip to content

Commit

Permalink
DOM: Rename EventTarget#on() to EventTarget#when()
Browse files Browse the repository at this point in the history
See the discussion in WICG/observable#39,
which led to this decision, and
WICG/observable#161 for the corresponding spec
rename.

R=jarhar

Bug: 40282760
Change-Id: I9cd744460a3545c74fb34a0418c6ffddc5e6d4e1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5730072
Reviewed-by: Joey Arhar <jarhar@chromium.org>
Commit-Queue: Dominic Farolino <dom@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1340875}
  • Loading branch information
domfarolino authored and chromium-wpt-export-bot committed Aug 13, 2024
1 parent 49e35fa commit c2d2309
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion dom/observable/tentative/observable-constructor.window.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ promise_test(async t => {
// 1. A traditional event listener
// 2. An observable
event_target.addEventListener('customevent', e => parentResults.push(e));
const source = event_target.on('customevent');
const source = event_target.when('customevent');
source.subscribe(e => parentResults.push(e));
// Detach the iframe and fire an event at the event target. The parent will
Expand Down
16 changes: 8 additions & 8 deletions dom/observable/tentative/observable-event-target.any.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
test(() => {
const target = new EventTarget();
assert_implements(target.on, "The EventTarget interface has an `on` method");
assert_equals(typeof target.on, "function",
"EventTarget should have the on method");
assert_implements(target.when, "The EventTarget interface has an `when` method");
assert_equals(typeof target.when, "function",
"EventTarget should have the when method");

const testEvents = target.on("test");
const testEvents = target.when("test");
assert_true(testEvents instanceof Observable,
"EventTarget.on returns an Observable");
"EventTarget.when() returns an Observable");

const results = [];
testEvents.subscribe({
Expand All @@ -24,11 +24,11 @@ test(() => {

target.dispatchEvent(event);
assert_array_equals(results, [event, event]);
}, "EventTarget.on() returns an Observable");
}, "EventTarget.when() returns an Observable");

test(() => {
const target = new EventTarget();
const testEvents = target.on("test");
const testEvents = target.when("test");
const ac = new AbortController();
const results = [];
testEvents.subscribe({
Expand Down Expand Up @@ -58,7 +58,7 @@ test(() => {

test(() => {
const target = new EventTarget();
const testEvents = target.on("test");
const testEvents = target.when("test");
const results = [];
testEvents.subscribe(e => results.push(e));
testEvents.subscribe(e => results.push(e));
Expand Down
6 changes: 3 additions & 3 deletions dom/observable/tentative/observable-event-target.window.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ test(() => {
document.querySelector('body').appendChild(document.createElement('div'));

const body = document.querySelector('body');
const captureObservable = body.on('click', {capture: true});
const bubbleObservable = body.on('click', {capture: false});
const captureObservable = body.when('click', {capture: true});
const bubbleObservable = body.when('click', {capture: false});

const results = [];
captureObservable.subscribe(e => results.push(e.eventPhase));
Expand All @@ -24,7 +24,7 @@ test(() => {
test(() => {
const target = new EventTarget();

const observable = target.on('event', {passive: true});
const observable = target.when('event', {passive: true});
observable.subscribe(event => {
assert_false(event.defaultPrevented);
// Should do nothing, since `observable` is "passive".
Expand Down
2 changes: 1 addition & 1 deletion dom/observable/tentative/observable-from.any.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ test(() => {

test(() => {
const target = new EventTarget();
const observable = target.on('custom');
const observable = target.when('custom');
const from_observable = Observable.from(observable);
assert_equals(observable, from_observable);
}, "from(): Given an observable, it returns that exact observable");
Expand Down
2 changes: 1 addition & 1 deletion dom/observable/tentative/observable-inspect.any.js
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ test(() => {

const controller = new AbortController();

self.on('error').take(1).subscribe(e =>
self.when('error').take(1).subscribe(e =>
results.push(e.message + ', from report exception'));

result.subscribe({
Expand Down

0 comments on commit c2d2309

Please sign in to comment.