Skip to content

Commit

Permalink
DOM: Introduce SubscribeOptions for Observable API
Browse files Browse the repository at this point in the history
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 WICG/observable#85 and
WICG/observable#71 for any relevant design
discussion.

[email protected]

Bug: 1485981
Change-Id: I9b9f9cf26cb8b7a71d2aab7811ad681386cbfd5a
  • Loading branch information
domfarolino authored and chromium-wpt-export-bot committed Nov 21, 2023
1 parent 096d789 commit 665db9f
Showing 1 changed file with 9 additions and 14 deletions.
23 changes: 9 additions & 14 deletions dom/observable/tentative/observable-constructor.any.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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()`");
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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()");
Expand Down

0 comments on commit 665db9f

Please sign in to comment.