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 windowWhen #291

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion rxjs-docs
Submodule rxjs-docs deleted from 5059b4
83 changes: 81 additions & 2 deletions src/operator-docs/transformation/windowWhen.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,85 @@
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 <a href="#/operators/bufferWhen" class="markdown-code">bufferWhen</a>,
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 <span class="markdown-code">closingSelector</span> 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: `
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
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please use es6 imports and pipe operator.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

.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',
url: 'http://jsbin.com/zegowub/embed?js,console,output'
}
}
],
relatedOperators: [
'window',
'windowCount',
'windowTime',
'windowToggle',
'bufferWhen'
]
};