Skip to content
This repository was archived by the owner on Oct 1, 2018. It is now read-only.

Commit 7f3ce3c

Browse files
Merge pull request #167 from mustafamg/doc-do-branch
docs(operators): add documentation for operator do
2 parents 1ed1390 + 5d2eb98 commit 7f3ce3c

File tree

1 file changed

+69
-2
lines changed
  • src/operator-docs/utility

1 file changed

+69
-2
lines changed

src/operator-docs/utility/do.ts

Lines changed: 69 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,73 @@
11
import { OperatorDoc } from '../operator.model';
22

33
export const doOperator: OperatorDoc = {
4-
'name': 'do',
5-
'operatorType': 'utility'
4+
name: 'do',
5+
operatorType: 'utility',
6+
signature:
7+
'public do(nextOrObserver: Observer | function, error: function, complete: function): Observable',
8+
parameters: [
9+
{
10+
name: 'nextOrObserver',
11+
type: 'Observer|function',
12+
attribute: 'optional',
13+
description: 'A normal Observer object or a callback for `next`.'
14+
},
15+
{
16+
name: 'error',
17+
type: 'function',
18+
attribute: 'optional',
19+
description: 'Callback for errors in the source.'
20+
},
21+
{
22+
name: 'complete',
23+
type: 'function',
24+
attribute: 'optional',
25+
description: 'Callback for the completion of the source.'
26+
}
27+
],
28+
marbleUrl: 'http://reactivex.io/rxjs/img/do.png',
29+
shortDescription: {
30+
description: `Perform a side effect for every emission on the source Observable, but return
31+
an Observable that is identical to the source.
32+
<span class="informal">Intercepts each emission on the source and runs a
33+
function, but returns an output which is identical to the source as long as errors don't
34+
occur.</span>`
35+
},
36+
walkthrough: {
37+
description: `
38+
<p>Returns a mirrored Observable of the source Observable,
39+
but modified so that the provided Observer is called to perform a side effect for every
40+
value, error, and completion emitted by the source. Any errors that are thrown in
41+
the aforementioned Observer or handlers are safely sent down the error path
42+
of the output Observable.
43+
</p>
44+
<p>
45+
This operator is useful for debugging your Observables for the correct values
46+
or performing other side effects.
47+
</p>
48+
<p>
49+
Note: this is different to a <code>subscribe</code> on the Observable. If the Observable
50+
returned by <code>do</code> is not subscribed, the side effects specified by the
51+
Observer will never happen. <code>do</code> therefore simply spies on existing
52+
execution, it does not trigger an execution to happen like <code>subscribe</code> does.</p>
53+
`
54+
},
55+
examples: [
56+
{
57+
name:
58+
'Map every click to the clientX position of that click, while also logging the click event',
59+
code: `
60+
var clicks = Rx.Observable.fromEvent(document, 'click');
61+
var positions = clicks
62+
.do(ev => console.log(ev.type))
63+
.map(ev => ev.clientX);
64+
positions.subscribe(x => console.log(x));
65+
`,
66+
externalLink: {
67+
platform: 'JSBin',
68+
url: 'http://jsbin.com/mikiqub/edit?js,console,output'
69+
}
70+
}
71+
],
72+
relatedOperators: ['map', 'subscribe']
673
};

0 commit comments

Comments
 (0)