From d34f58c98d9114ccd9c2cfae89c3fa375b53809f Mon Sep 17 00:00:00 2001 From: Dominic Farolino Date: Mon, 29 Jul 2024 10:05:25 -0700 Subject: [PATCH] DOM: Rename EventTarget#on() to EventTarget#when() See the discussion in https://github.com/WICG/observable/issues/39, which led to this decision, and https://github.com/WICG/observable/pull/161 for the corresponding spec rename. R=jarhar Bug: 40282760 Change-Id: I9cd744460a3545c74fb34a0418c6ffddc5e6d4e1 --- .../tentative/observable-constructor.window.js | 2 +- .../tentative/observable-event-target.any.js | 16 ++++++++-------- .../tentative/observable-event-target.window.js | 6 +++--- dom/observable/tentative/observable-from.any.js | 2 +- .../tentative/observable-inspect.any.js | 2 +- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/dom/observable/tentative/observable-constructor.window.js b/dom/observable/tentative/observable-constructor.window.js index d2b597c819054f..878fc456c10287 100644 --- a/dom/observable/tentative/observable-constructor.window.js +++ b/dom/observable/tentative/observable-constructor.window.js @@ -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 diff --git a/dom/observable/tentative/observable-event-target.any.js b/dom/observable/tentative/observable-event-target.any.js index 0f7ace2acc0794..9f5d5541a039c4 100644 --- a/dom/observable/tentative/observable-event-target.any.js +++ b/dom/observable/tentative/observable-event-target.any.js @@ -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({ @@ -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({ @@ -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)); diff --git a/dom/observable/tentative/observable-event-target.window.js b/dom/observable/tentative/observable-event-target.window.js index 77a137a3622e8d..fa3ae1d3b020e1 100644 --- a/dom/observable/tentative/observable-event-target.window.js +++ b/dom/observable/tentative/observable-event-target.window.js @@ -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)); @@ -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". diff --git a/dom/observable/tentative/observable-from.any.js b/dom/observable/tentative/observable-from.any.js index 80408ddced7ef5..900362d8c3acee 100644 --- a/dom/observable/tentative/observable-from.any.js +++ b/dom/observable/tentative/observable-from.any.js @@ -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"); diff --git a/dom/observable/tentative/observable-inspect.any.js b/dom/observable/tentative/observable-inspect.any.js index 8aff741d2670db..2b67dd9f3d3a83 100644 --- a/dom/observable/tentative/observable-inspect.any.js +++ b/dom/observable/tentative/observable-inspect.any.js @@ -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({