From b63a81a27f91f09ef0aff967e2cd7dc9ce84127d Mon Sep 17 00:00:00 2001 From: Hardik Pithva Date: Tue, 6 Feb 2018 14:08:53 +0530 Subject: [PATCH 1/4] docs(operators): add documentation for windowWhen --- .../transformation/windowWhen.ts | 57 ++++++++++++++++++- 1 file changed, 55 insertions(+), 2 deletions(-) diff --git a/src/operator-docs/transformation/windowWhen.ts b/src/operator-docs/transformation/windowWhen.ts index 90829e20..97d7a8c7 100644 --- a/src/operator-docs/transformation/windowWhen.ts +++ b/src/operator-docs/transformation/windowWhen.ts @@ -1,6 +1,59 @@ import { OperatorDoc } from '../operator.model'; export const windowWhen: OperatorDoc = { - 'name': 'windowWhen', - 'operatorType': 'transformation' + name: 'windowWhen', + operatorType: 'transformation', + signature: `public windowWhen(closingSelector: function(): Observable): Observable`, + parameters: [ + { + name: 'closingSelector', + type: 'function(): Observable', + attribute: '', + description: ` + A function that takes no arguments and returns an Observable that signals + (on either 'next' or 'complete') when to close the previous window and start a new one.` + } + ], + marbleUrl: 'http://reactivex.io/rxjs/img/windowWhen.png', + shortDescription: { + description: ` + Branch out the source Observable values as a nested Observable using a factory function of + closing Observables to determine when to start a new window.`, + extras: [ + { + type: 'Tip', + text: ` + It's like bufferWhen, + but emits a nested Observable instead of an array. + ` + } + ] + }, + walkthrough: { + description: ` + Returns an Observable that emits windows of items it collects from the source Observable. The output Observable + emits connected, non-overlapping windows. It emits the current window and opens a new one whenever the Observable + produced by the specified closingSelector function emits an item. The first + window is opened immediately when subscribing to the output Observable.` + }, + examples: [ + { + name: + 'Emit only the first two clicks events in every window of [1-5] random seconds', + code: ` + + `, + externalLink: { + platform: 'JSBin', + url: 'http://jsbin.com/zegowub/embed?js,console,output' + } + } + ], + relatedOperators: [ + 'window', + 'windowCount', + 'windowTime', + 'windowToggle', + 'bufferWhen' + ] }; From a98869140663e6556fcf19db5b0a1e8e5d194749 Mon Sep 17 00:00:00 2001 From: Hardik Pithva Date: Thu, 1 Mar 2018 22:56:55 +0530 Subject: [PATCH 2/4] fix: remove submodule --- rxjs-docs | 1 - 1 file changed, 1 deletion(-) delete mode 160000 rxjs-docs diff --git a/rxjs-docs b/rxjs-docs deleted file mode 160000 index 5059b48c..00000000 --- a/rxjs-docs +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 5059b48c083853b48eeabdc2272c56edf4e2443b From a0c06454268453ea6c19f890c3500146896f09ae Mon Sep 17 00:00:00 2001 From: Hardik Pithva Date: Thu, 1 Mar 2018 23:19:15 +0530 Subject: [PATCH 3/4] fix(operators): add code snippet --- .../transformation/windowWhen.ts | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/operator-docs/transformation/windowWhen.ts b/src/operator-docs/transformation/windowWhen.ts index 97d7a8c7..b874b2e0 100644 --- a/src/operator-docs/transformation/windowWhen.ts +++ b/src/operator-docs/transformation/windowWhen.ts @@ -41,7 +41,33 @@ export const windowWhen: OperatorDoc = { name: 'Emit only the first two clicks events in every window of [1-5] random seconds', code: ` + import { interval } from "rxjs/observable/interval"; + import { mergeAll, windowWhen } from "rxjs/operators"; + const clicks = Rx.Observable.fromEvent(document, 'click'); + const result = clicks + .windowWhen(() => interval(1000 + Math.random() * 4000)) + .map(win => win.take(2)) // each window has at most 2 emissions + .mergeAll(); // flatten the Observable-of-Observables + result.subscribe(x => console.log(x)); + + /* + Example console output + [object MouseEvent] { + altKey: false, + AT_TARGET: 2, + bubbles: true, + BUBBLING_PHASE: 3, + button: 0, + buttons: 0, + cancelable: true, + cancelBubble: false, + CAPTURING_PHASE: 1, + clientX: 80, + clientY: 70, + .... //Entire object properties + } + */ `, externalLink: { platform: 'JSBin', From b66c39a0b2b53a0c672515c51709e10033141f70 Mon Sep 17 00:00:00 2001 From: Hardik Pithva Date: Sun, 1 Apr 2018 17:40:24 +0530 Subject: [PATCH 4/4] fix(operators): update code snippet --- .../transformation/windowWhen.ts | 52 ++++++++++--------- 1 file changed, 27 insertions(+), 25 deletions(-) diff --git a/src/operator-docs/transformation/windowWhen.ts b/src/operator-docs/transformation/windowWhen.ts index b874b2e0..e831ce7c 100644 --- a/src/operator-docs/transformation/windowWhen.ts +++ b/src/operator-docs/transformation/windowWhen.ts @@ -41,33 +41,35 @@ export const windowWhen: OperatorDoc = { name: 'Emit only the first two clicks events in every window of [1-5] random seconds', code: ` - import { interval } from "rxjs/observable/interval"; - import { mergeAll, windowWhen } from "rxjs/operators"; + import { fromEvent } from 'rxjs/observable/fromEvent'; + import { interval } from 'rxjs/observable/interval'; + import { mergeAll, tap, windowWhen } from 'rxjs/operators'; - const clicks = Rx.Observable.fromEvent(document, 'click'); - const result = clicks - .windowWhen(() => interval(1000 + Math.random() * 4000)) - .map(win => win.take(2)) // each window has at most 2 emissions - .mergeAll(); // flatten the Observable-of-Observables - result.subscribe(x => console.log(x)); + const clicks = fromEvent(document, 'click'); + const result = clicks.pipe( + windowWhen(() => interval(3000)), + tap(() => console.log('Window Initated!')) + ); + result.pipe(mergeAll()).subscribe(x => console.log(x)); - /* - Example console output - [object MouseEvent] { - altKey: false, - AT_TARGET: 2, - bubbles: true, - BUBBLING_PHASE: 3, - button: 0, - buttons: 0, - cancelable: true, - cancelBubble: false, - CAPTURING_PHASE: 1, - clientX: 80, - clientY: 70, - .... //Entire object properties - } - */ + /* + Example console output + 'Window Initated!' + 'Window Initated!' + 'Window Initated!' + 'Window Initated!' //clicked on document + [object MouseEvent] { + altKey: false, + AT_TARGET: 2, + bubbles: true, + BUBBLING_PHASE: 3, + button: 0, + buttons: 0, + cancelable: true, + cancelBubble: false, + .... //Entire object properties + } + */ `, externalLink: { platform: 'JSBin',