This repository was archived by the owner on Oct 1, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 61
docs(operators): add documentation for operator do #167
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
db86d64
docs(operators): add documentation for operator 'do'
mustafamg 5e862e2
Merge remote-tracking branch 'upstream/master' into doc-do-branch
mustafamg f29f509
docs(operators): add documentation for operator do
mustafamg 5eb3cab
Merge branch 'master' into doc-do-branch
mustafamg 37ffd9d
Merge branch 'master' into doc-do-branch
sumitarora f7ac77c
docs(operators): add documentation for operator do
mustafamg 5d2eb98
Merge branch 'master' into doc-do-branch
sumitarora File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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>Returns a mirrored Observable of the source Observable, | ||
| 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.type)) | ||
| .map(ev => ev.clientX); | ||
| positions.subscribe(x => console.log(x)); | ||
| `, | ||
| externalLink: { | ||
| platform: 'JSBin', | ||
| url: 'http://jsbin.com/mikiqub/edit?js,console,output' | ||
|
Collaborator
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.
Contributor
Author
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
Contributor
Author
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'] | ||
| }; | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
Uh oh!
There was an error while loading. Please reload this page.
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.