Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First try at adding a flatMap spec #123

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 64 additions & 1 deletion spec.bs
Original file line number Diff line number Diff line change
Expand Up @@ -827,9 +827,72 @@ For now, see [https://github.com/wicg/observable#operators](https://github.com/w
<div algorithm>
The <dfn for=Observable method><code>flatMap(|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 |queue| be a new [=list=] to keep track of items emitted by the source observable that need to be processed.

1. Let |activeInnerSubscription| be false, indicating whether an inner subscription is currently active.

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

: [=internal observer/next steps=]
:: 1. If |activeInnerSubscription| is true, then:

1. [=list/Append=] the passed in <var ignore>value</var> to |queue|.

1. Return.

1. Otherwise:

1. Set |activeInnerSubscription| to true.

1. Let |innerObservable| be the result of [=Invoke=] |mapper| with the passed in <var ignore>value</var>.

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

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

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

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

: [=internal observer/complete steps=]
:: 1. If |queue| is not empty, then:

1. Let |nextValue| be [=list/Remove=] the first item from |queue|.

1. Repeat the steps above starting from the step where |innerObservable| is obtained by invoking |mapper| with |nextValue|.

1. Otherwise:

1. Set |activeInnerSubscription| to false.

1. If |sourceObserver| has also completed, run |subscriber|'s {{Subscriber/complete()}} method.

1. Let |innerOptions| be a new {{SubscribeOptions}} whose {{SubscribeOptions/signal}} is |subscriber|'s [=Subscriber/signal=].

1. <a for=Observable lt="subscribe to an Observable">Subscribe</a> to |innerObservable| given |innerObserver| and |innerOptions|.

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

: [=internal observer/complete steps=]
:: If |activeInnerSubscription| is false, and |queue| is empty, run |subscriber|'s {{Subscriber/complete()}} method.

1. Let |options| be a new {{SubscribeOptions}} whose {{SubscribeOptions/signal}} is |subscriber|'s [=Subscriber/signal=].

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

1. Return |observable|.
</div>


<div algorithm>
The <dfn for=Observable method><code>finally(|callback|)</code></dfn> method steps are:

Expand Down
Loading