-
Notifications
You must be signed in to change notification settings - Fork 62
docs(operators): add documentation for operator do #167
Changes from 2 commits
db86d64
5e862e2
f29f509
5eb3cab
37ffd9d
f7ac77c
5d2eb98
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,73 @@ | ||
import { OperatorDoc } from '../operator.model'; | ||
|
||
export const doOperator: OperatorDoc = { | ||
'name': 'do', | ||
'operatorType': 'utility' | ||
name: 'do', | ||
operatorType: 'utility', | ||
signature: | ||
'public do(nextOrObserver: Observer | function, error: function, complete: function): Observable', | ||
parameters: [ | ||
{ | ||
name: 'nextOrObserver', | ||
type: 'Observer|function', | ||
attribute: 'optional', | ||
description: 'A normal Observer object or a callback for `next`.' | ||
}, | ||
{ | ||
name: 'error', | ||
type: 'function', | ||
attribute: 'optional', | ||
description: 'Callback for errors in the source.' | ||
}, | ||
{ | ||
name: 'complete', | ||
type: 'function', | ||
attribute: 'optional', | ||
description: 'Callback for the completion of the source.' | ||
} | ||
], | ||
marbleUrl: 'http://reactivex.io/rxjs/img/do.png', | ||
shortDescription: { | ||
description: `Perform a side effect for every emission on the source Observable, but return | ||
an Observable that is identical to the source. | ||
<span class="informal">Intercepts each emission on the source and runs a | ||
function, but returns an output which is identical to the source as long as errors don't | ||
occur.</span>` | ||
}, | ||
walkthrough: { | ||
description: ` | ||
<p><code>do</code> Returns a mirrored Observable of the source Observable, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. returns (without the R) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay, will do that. |
||
but modified so that the provided Observer is called to perform a side effect for every | ||
value, error, and completion emitted by the source. Any errors that are thrown in | ||
the aforementioned Observer or handlers are safely sent down the error path | ||
of the output Observable. | ||
</p> | ||
<p> | ||
This operator is useful for debugging your Observables for the correct values | ||
or performing other side effects. | ||
</p> | ||
<p> | ||
Note: this is different to a <code>subscribe</code> on the Observable. If the Observable | ||
returned by <code>do</code> is not subscribed, the side effects specified by the | ||
Observer will never happen. <code>do</code> therefore simply spies on existing | ||
execution, it does not trigger an execution to happen like <code>subscribe</code> does.</p> | ||
` | ||
}, | ||
examples: [ | ||
{ | ||
name: | ||
'Map every click to the clientX position of that click, while also logging the click event', | ||
code: ` | ||
var clicks = Rx.Observable.fromEvent(document, 'click'); | ||
var positions = clicks | ||
.do(ev => console.log(ev)) | ||
.map(ev => ev.clientX); | ||
positions.subscribe(x => console.log(x)); | ||
`, | ||
externalLink: { | ||
platform: 'JSBin', | ||
url: 'http://jsbin.com/mikiqub/edit?js,console,output' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just one small change. Instead of logging whole event in js bin which outputs the whole event details in jsbin.
Could you just do event type. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay, thanks for the comment There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
} | ||
} | ||
], | ||
relatedOperators: ['map', 'subscribe'] | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could mark the optional parameters with a question mark:
public do(nextOrObserver?: Observer | function, error?: function, complete?: function): Observable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with you it will be better to have a distinctive mark for optional parameters. My only concern is that this is inconsistent with the rest of the document. I think you should make this as a suggestion for the full documentation, then all contributors can follow it as a rule.
Right now, I don't think I should be the only one making this change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've opened #168 which encompass this suggestion with others.