From db86d64467cba74bf9186febec63bca67335e086 Mon Sep 17 00:00:00 2001 From: "Mustafa M. Gamal" Date: Thu, 23 Nov 2017 04:12:58 +0200 Subject: [PATCH 1/3] docs(operators): add documentation for operator 'do' --- src/operator-docs/utility/do.ts | 71 ++++++++++++++++++++++++++++++++- 1 file changed, 69 insertions(+), 2 deletions(-) diff --git a/src/operator-docs/utility/do.ts b/src/operator-docs/utility/do.ts index 55609103..fea5f531 100644 --- a/src/operator-docs/utility/do.ts +++ b/src/operator-docs/utility/do.ts @@ -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. + 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.` + }, + walkthrough: { + description: ` +

do 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. +

+

+ This operator is useful for debugging your Observables for the correct values + or performing other side effects. +

+

+ Note: this is different to a subscribe on the Observable. If the Observable + returned by do is not subscribed, the side effects specified by the + Observer will never happen. do therefore simply spies on existing + execution, it does not trigger an execution to happen like subscribe does.

+ ` + }, + 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' + } + } + ], + relatedOperators: ['map', 'subscribe'] }; From f29f50919212e070cbc3d524f8c85378b69af86d Mon Sep 17 00:00:00 2001 From: "Mustafa M. Gamal" Date: Fri, 24 Nov 2017 20:05:55 +0200 Subject: [PATCH 2/3] docs(operators): add documentation for operator do --- src/operator-docs/utility/do.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/operator-docs/utility/do.ts b/src/operator-docs/utility/do.ts index fea5f531..fddedc77 100644 --- a/src/operator-docs/utility/do.ts +++ b/src/operator-docs/utility/do.ts @@ -35,7 +35,7 @@ export const doOperator: OperatorDoc = { }, walkthrough: { description: ` -

do Returns a mirrored Observable of the source Observable, +

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 From f7ac77cea9a374305e134f9fc820874883ef2160 Mon Sep 17 00:00:00 2001 From: "Mustafa M. Gamal" Date: Mon, 27 Nov 2017 23:28:22 +0200 Subject: [PATCH 3/3] docs(operators): add documentation for operator do --- src/operator-docs/utility/do.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/operator-docs/utility/do.ts b/src/operator-docs/utility/do.ts index fddedc77..b9c543a2 100644 --- a/src/operator-docs/utility/do.ts +++ b/src/operator-docs/utility/do.ts @@ -59,7 +59,7 @@ export const doOperator: OperatorDoc = { code: ` var clicks = Rx.Observable.fromEvent(document, 'click'); var positions = clicks - .do(ev => console.log(ev)) + .do(ev => console.log(ev.type)) .map(ev => ev.clientX); positions.subscribe(x => console.log(x)); `,