From dbd13167a668830be3817fa612b2f00299d3cd76 Mon Sep 17 00:00:00 2001 From: Dominic Farolino Date: Tue, 21 Nov 2023 15:34:47 -0800 Subject: [PATCH] DOM: Introduce SubscribeOptions for Observable API This PR separates the AbortSignal from the callbacks passed into `subscribe()` via the `Observer` dictionary, into its own dictionary, where future options may live. This is a particularly useful ergonomic change for chaining Observables together. See https://github.com/WICG/observable/pull/85 and https://github.com/WICG/observable/issues/71 for any relevant design discussion. R=masonf@chromium.org Bug: 1485981 Change-Id: I9b9f9cf26cb8b7a71d2aab7811ad681386cbfd5a Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5046377 Commit-Queue: Dominic Farolino Reviewed-by: Mason Freed Cr-Commit-Position: refs/heads/main@{#1227666} --- .../tentative/observable-constructor.any.js | 23 ++++++++----------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/dom/observable/tentative/observable-constructor.any.js b/dom/observable/tentative/observable-constructor.any.js index 3a6355c07a8d4b..851369e2c98162 100644 --- a/dom/observable/tentative/observable-constructor.any.js +++ b/dom/observable/tentative/observable-constructor.any.js @@ -186,7 +186,7 @@ test(t => { initialSignalAborted = subscriber.signal.aborted; }); - source.subscribe({signal: AbortSignal.abort('Initially aborted')}); + source.subscribe({}, {signal: AbortSignal.abort('Initially aborted')}); assert_false(initialActivity); assert_true(initialSignalAborted); assert_equals(innerSubscriber.signal.reason, 'Initially aborted'); @@ -198,7 +198,7 @@ test(() => { const source = new Observable(subscriber => outerSubscriber = subscriber); const controller = new AbortController(); - source.subscribe({signal: controller.signal}); + source.subscribe({}, {signal: controller.signal}); assert_not_equals(controller.signal, outerSubscriber.signal); }, "Subscriber#signal is not the same AbortSignal as the one passed into `subscribe()`"); @@ -555,9 +555,8 @@ test(() => { source.subscribe({ // This should never get called. If it is, the array assertion below will fail. next: (x) => results.push(x), - complete: () => results.push('complete()'), - signal: ac.signal, - }); + complete: () => results.push('complete()') + }, {signal: ac.signal}); ac.signal.addEventListener('abort', () => { results.push('outer abort handler'); @@ -596,9 +595,8 @@ test(t => { } }, error: () => results.push('error'), - complete: () => results.push('complete'), - signal: ac.signal, - }); + complete: () => results.push('complete') + }, {signal: ac.signal}); assert_array_equals( results, @@ -665,9 +663,7 @@ test(() => { }); const ac = new AbortController(); - source.subscribe({ - signal: ac.signal, - }); + source.subscribe({}, {signal: ac.signal}); assert_false(addTeardownCalled, "Teardown is not be called upon subscription"); ac.abort(); @@ -809,9 +805,8 @@ test(() => { source.subscribe({ next: (x) => results.push(x), error: (error) => results.push(error), - complete: () => results.push('complete'), - signal: ac.signal, - }); + complete: () => results.push('complete') + }, {signal: ac.signal}); assert_array_equals(results, []); assert_true(firstTeardownInvokedSynchronously, "First teardown callback is invoked during addTeardown()");