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

docs(operators): add documentation for operator do #167

Merged
merged 7 commits into from
Nov 28, 2017
71 changes: 69 additions & 2 deletions src/operator-docs/utility/do.ts
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',
Copy link
Contributor

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

Copy link
Contributor Author

@mustafamg mustafamg Nov 24, 2017

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.

Copy link
Contributor

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.

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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

returns (without the R)

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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'
Copy link
Collaborator

Choose a reason for hiding this comment

The 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.

[object MouseEvent] {
  altKey: false,
  AT_TARGET: 2,
  bubbles: true,
  BUBBLING_PHASE: 3,
  button: 0,
  buttons: 0,
  cancelable: true,
  cancelBubble: false,
  CAPTURING_PHASE: 1,
  clientX: 182,
  clientY: 292,
  composed: true,
  composedPath: function composedPath() { [native code] },
  ctrlKey: false,
  currentTarget: [object HTMLDocument] {
    activeElement: [object HTMLBodyElement] { ... },
    addEventListener: function addEventListener() { [native code] },
    adoptNode: function adoptNode() { [native code] },

Could you just do event type. .do(ev => console.log(ev)) to .do(ev => console.log(ev.type))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, thanks for the comment

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

}
}
],
relatedOperators: ['map', 'subscribe']
};