Skip to content

Commit

Permalink
Spec the map() operator (#110)
Browse files Browse the repository at this point in the history
  • Loading branch information
domfarolino authored Feb 8, 2024
1 parent 35b0376 commit 29fabd5
Showing 1 changed file with 40 additions and 1 deletion.
41 changes: 40 additions & 1 deletion spec.bs
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,46 @@ For now, see [https://github.com/wicg/observable#operators](https://github.com/w
<div algorithm>
The <dfn for=Observable method><code>map(|mapper|)</code></dfn> method steps are:

1. <span class=XXX>TODO: Spec this and use |mapper|.</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 |idx| be an {{unsigned long long}}, initially 0.

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

: [=internal observer/next steps=]
:: 1. [=Invoke=] |mapper| with the passed in <var ignore>value</var>, and |idx|, and let
|mappedValue| 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. Increment |idx|.

1. Run |subscriber|'s {{Subscriber/next()}} method, given |mappedValue|.

: [=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 29fabd5

Please sign in to comment.