Skip to content

Commit

Permalink
Spec some(), every(), find() operators
Browse files Browse the repository at this point in the history
  • Loading branch information
domfarolino committed Apr 8, 2024
1 parent 5fac9fd commit 5fb2b8e
Showing 1 changed file with 132 additions and 3 deletions.
135 changes: 132 additions & 3 deletions spec.bs
Original file line number Diff line number Diff line change
Expand Up @@ -1112,19 +1112,148 @@ For now, see [https://github.com/wicg/observable#operators](https://github.com/w
<div algorithm>
The <dfn for=Observable method><code>every(|predicate|, |options|)</code></dfn> method steps are:

1. <span class=XXX>TODO: Spec this and use |predicate| and |options|.</span>
1. Let |p| [=a new promise=].

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

1. Let |internal options| be a new {{SubscribeOptions}} whose {{SubscribeOptions/signal}} is the
result of [=creating a dependent abort signal=] from the list
«|controller|'s [=AbortController/signal=], |options|'s
{{SubscribeOptions/signal}} if non-null», using {{AbortSignal}}, and the [=current realm=].

1. If |internal options|'s {{SubscribeOptions/signal}} is [=AbortSignal/aborted=], then:

1. [=Reject=] |p| with |internal options|'s {{SubscribeOptions/signal}}'s
[=AbortSignal/abort reason=].

1. Return |p|.

1. [=AbortSignal/add|Add the following abort algorithm=] to |internal options|'s
{{SubscribeOptions/signal}}:

1. [=Reject=] |p| with |internal options|'s {{SubscribeOptions/signal}}'s [=AbortSignal/abort
reason=].

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

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

If <a spec=webidl lt="an exception was thrown">an exception |E| was thrown</a>, then
[=reject=] |p| with |E|, and [=AbortController/signal abort=] |controller| with |E|.

1. If |passed| is false, then [=resolve=] |p| with false, and [=AbortController/signal
abort=] |controller|.

: [=internal observer/error steps=]
:: [=Reject=] |p| with the passed in <var ignore>error</var>.

: [=internal observer/complete steps=]
:: [=Resolve=] |p| with true.

1. <a for=Observable lt="subscribe to an Observable">Subscribe</a> to [=this=] given |observer|
and |internal options|.

1. Return |p|.
</div>

<div algorithm>
The <dfn for=Observable method><code>find(|predicate|, |options|)</code></dfn> method steps are:

1. <span class=XXX>TODO: Spec this and use |predicate| and |options|.</span>
1. Let |p| [=a new promise=].

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

1. Let |internal options| be a new {{SubscribeOptions}} whose {{SubscribeOptions/signal}} is the
result of [=creating a dependent abort signal=] from the list
«|controller|'s [=AbortController/signal=], |options|'s
{{SubscribeOptions/signal}} if non-null», using {{AbortSignal}}, and the [=current realm=].

1. If |internal options|'s {{SubscribeOptions/signal}} is [=AbortSignal/aborted=], then:

1. [=Reject=] |p| with |internal options|'s {{SubscribeOptions/signal}}'s
[=AbortSignal/abort reason=].

1. Return |p|.

1. [=AbortSignal/add|Add the following abort algorithm=] to |internal options|'s
{{SubscribeOptions/signal}}:

1. [=Reject=] |p| with |internal options|'s {{SubscribeOptions/signal}}'s [=AbortSignal/abort
reason=].

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

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

If <a spec=webidl lt="an exception was thrown">an exception |E| was thrown</a>, then
[=reject=] |p| with |E|, and [=AbortController/signal abort=] |controller| with |E|.

1. If |passed| is true, then [=resolve=] |p| with |value|, and [=AbortController/signal
abort=] |controller|.

: [=internal observer/error steps=]
:: [=Reject=] |p| with the passed in <var ignore>error</var>.

: [=internal observer/complete steps=]
:: [=Resolve=] |p| with false.

1. <a for=Observable lt="subscribe to an Observable">Subscribe</a> to [=this=] given |observer|
and |internal options|.

1. Return |p|.
</div>

<div algorithm>
The <dfn for=Observable method><code>some(|predicate|, |options|)</code></dfn> method steps are:

1. <span class=XXX>TODO: Spec this and use |predicate| and |options|.</span>
1. Let |p| [=a new promise=].

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

1. Let |internal options| be a new {{SubscribeOptions}} whose {{SubscribeOptions/signal}} is the
result of [=creating a dependent abort signal=] from the list
«|controller|'s [=AbortController/signal=], |options|'s
{{SubscribeOptions/signal}} if non-null», using {{AbortSignal}}, and the [=current realm=].

1. If |internal options|'s {{SubscribeOptions/signal}} is [=AbortSignal/aborted=], then:

1. [=Reject=] |p| with |internal options|'s {{SubscribeOptions/signal}}'s
[=AbortSignal/abort reason=].

1. Return |p|.

1. [=AbortSignal/add|Add the following abort algorithm=] to |internal options|'s
{{SubscribeOptions/signal}}:

1. [=Reject=] |p| with |internal options|'s {{SubscribeOptions/signal}}'s [=AbortSignal/abort
reason=].

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

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

If <a spec=webidl lt="an exception was thrown">an exception |E| was thrown</a>, then
[=reject=] |p| with |E|, and [=AbortController/signal abort=] |controller| with |E|.

1. If |passed| is true, then [=resolve=] |p| with true, and [=AbortController/signal
abort=] |controller|.

: [=internal observer/error steps=]
:: [=Reject=] |p| with the passed in <var ignore>error</var>.

: [=internal observer/complete steps=]
:: [=Resolve=] |p| with false.

1. <a for=Observable lt="subscribe to an Observable">Subscribe</a> to [=this=] given |observer|
and |internal options|.

1. Return |p|.
</div>

<div algorithm>
Expand Down

0 comments on commit 5fb2b8e

Please sign in to comment.