docs: fix table in comparing observables guide (#22485)

PR Close #22485
This commit is contained in:
Ro Savage 2018-02-28 17:40:55 +13:00 committed by Kara Erickson
parent 66547d8fd0
commit 8d0f8bd657

View File

@ -89,47 +89,51 @@ promise.then(() => {
The following code snippets illustrate how the same kind of operation is defined using observables and promises. The following code snippets illustrate how the same kind of operation is defined using observables and promises.
<table> <table>
<tr> <thead>
<th>Operation</th> <tr>
<th>Observable</th> <th>Operation</th>
<th>Promise</th> <th>Observable</th>
</tr> <th>Promise</th>
<tr> </tr>
<td>Creation</td> </thead>
<td> <tbody>
<pre>new Observable((observer) => { <tr>
observer.next(123); <td>Creation</td>
});</pre> <td>
</td> <pre>new Observable((observer) => {
<td> observer.next(123);
<pre>new Promise((resolve, reject) => { });</pre>
resolve(123); </td>
});</pre> <td>
</td> <pre>new Promise((resolve, reject) => {
</tr> resolve(123);
<tr> });</pre>
<td>Transform</td> </td>
<td><pre>obs.map((value) => value * 2 );</pre></td> </tr>
<td><pre>promise.then((value) => value * 2);</pre></td> <tr>
</tr> <td>Transform</td>
<tr> <td><pre>obs.map((value) => value * 2 );</pre></td>
<td>Subscribe</td> <td><pre>promise.then((value) => value * 2);</pre></td>
<td> </tr>
<pre>sub = obs.subscribe((value) => { <tr>
console.log(value) <td>Subscribe</td>
});</pre> <td>
</td> <pre>sub = obs.subscribe((value) => {
<td> console.log(value)
<pre>promise.then((value) => { });</pre>
console.log(value); </td>
});</pre> <td>
</td> <pre>promise.then((value) => {
</tr> console.log(value);
<tr> });</pre>
<td>Unsubscribe</td> </td>
<td><pre>sub.unsubscribe();</pre></td> </tr>
<td>Implied by promise resolution.</td> <tr>
</tr> <td>Unsubscribe</td>
<td><pre>sub.unsubscribe();</pre></td>
<td>Implied by promise resolution.</td>
</tr>
</tbody>
</table> </table>
## Observables compared to events API ## Observables compared to events API