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 62
/
Copy pathwindowWhen.ts
87 lines (84 loc) · 2.93 KB
/
windowWhen.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import { OperatorDoc } from '../operator.model';
export const windowWhen: OperatorDoc = {
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 { fromEvent } from 'rxjs/observable/fromEvent';
import { interval } from 'rxjs/observable/interval';
import { mergeAll, tap, windowWhen } from 'rxjs/operators';
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
'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',
url: 'http://jsbin.com/zegowub/embed?js,console,output'
}
}
],
relatedOperators: [
'window',
'windowCount',
'windowTime',
'windowToggle',
'bufferWhen'
]
};