Skip to content

Commit

Permalink
Spec the filter() operator
Browse files Browse the repository at this point in the history
  • Loading branch information
domfarolino committed Feb 9, 2024
1 parent 29fabd5 commit 2c57f6f
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion spec.bs
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,43 @@ For now, see [https://github.com/wicg/observable#operators](https://github.com/w
<div algorithm>
The <dfn for=Observable method><code>filter(|predicate|)</code></dfn> method steps are:

1. <span class=XXX>TODO: Spec this and use |predicate|.</span>
1. Let |sourceObservable| be [=this=].

1. Let |observable| be a [=new=] {{Observable}} whose [=Observable/subscribe callback=] is an
algorithm that takes a {{Subscriber}} |subscriber| and does the following:

1. Let |controller| be a [=new=] {{AbortController}}.

1. Let |sourceObserver| be a new [=internal observer=], initialized as follows:

: [=internal observer/next steps=]
:: 1. [=Invoke=] |predicate| with the passed in |value|, and let |matches|
be the returned value.

If <a spec=webidl lt="an exception was thrown">an exception |E| was thrown</a>,
then run |subscriber|'s {{Subscriber/error()}} method, given |E|,
[=AbortController/signal abort=] |controller|, and abort these steps.

1. If |matches| is true, then run |subscriber|'s {{Subscriber/next()}} method, given
|value|.

: [=internal observer/error steps=]
:: Run |subscriber|'s {{Subscriber/error()}} method, given the passed in <var
ignore>error</var>.

: [=internal observer/complete steps=]
:: Run |subscriber|'s {{Subscriber/complete()}} method.

1. Let |signal| be the result of [=creating a dependent abort signal=] from the list
«|controller|'s [=AbortController/signal=], |subscriber|'s [=Subscriber/signal=]», using
{{AbortSignal}}, and the [=current realm=].

1. Let |options| be a new {{SubscribeOptions}} whose {{SubscribeOptions/signal}} is |signal|.

1. <a for=Observable lt="subscribe to an Observable">Subscribe</a> to |sourceObservable|
given |sourceObserver| and |options|.

1. Return |observable|.
</div>

<div algorithm>
Expand Down

0 comments on commit 2c57f6f

Please sign in to comment.