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 pathbufferCount.ts
156 lines (145 loc) · 3.92 KB
/
bufferCount.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
import { OperatorDoc } from '../operator.model';
export const bufferCount: OperatorDoc = {
name: 'bufferCount',
operatorType: 'transformation',
returnValue: 'Observable',
signature: ` bufferCount(bufferSize: number, startBufferEvery: number): Observable`,
parameters: [
{
name: 'bufferSize',
type: 'number',
attribute: '',
description: `The maximum size of the buffer emitted.`
},
{
name: 'startBufferEvery',
type: 'number',
attribute: 'optional',
description: `Interval at which to start a new buffer. For example if startBufferEvery is 2,
then a new buffer will be started on every other value from the source.
A new buffer is started at the beginning of the source by default.`
}
],
marbleUrl: 'http://reactivex.io/rxjs/img/bufferCount.png',
shortDescription: {
description: `
Buffers the source Observable values until the size hits the maximum <span class="markdown-code">bufferSize</span> given.
<span class="informal">
Collects values from the past as an array,
and emits that array only when its size reaches <span class="markdown-code">bufferSize</span>.
</span>`
},
walkthrough: {
description: `
Buffers a number of values from the source Observable
by <span class="markdown-code">bufferSize</span> then emits the buffer and clears it,
and starts a new buffer each <span class="markdown-code">startBufferEvery</span> values.
If <span class="markdown-code">startBufferEvery</span> is not provided or is null,
then new buffers are started immediately at the start of the source and when each buffer closes and is emitted.
`
},
examples: [
{
name: 'Every two clicks, emit those two click events as an array',
code: `
import { fromEvent } from 'rxjs/observable/fromEvent';
import { bufferCount } from 'rxjs/operators';
const clicks = fromEvent(document, 'click', e => ({x: e.clientX, y: e.clientY}));
const buffered = clicks.pipe(
bufferCount(2)
);
buffered.subscribe(x => console.log(x));
/*
Example console output:
[[object Object] {
x: 235,
y: 140
}, [object Object] {
x: 63,
y: 45
}]
[[object Object] {
x: 199,
y: 74
}, [object Object] {
x: 133,
y: 181
}]
[[object Object] {
x: 343,
y: 174
}, [object Object] {
x: 274,
y: 82
}]
*/
`,
externalLink: {
platform: 'JSBin',
url: 'http://jsbin.com/ceripaf/8/embed?js,console,output'
}
},
{
name: 'On every click, emit the last two click events as an array',
code: `
import { fromEvent } from 'rxjs/observable/fromEvent';
import { bufferCount } from 'rxjs/operators';
const clicks = fromEvent(document, 'click', e => ({x: e.clientX, y: e.clientY}));
const buffered = clicks.pipe(
bufferCount(2, 1)
);
buffered.subscribe(x => console.log(x));
/*
Example console output:
[[object Object] {
x: 241,
y: 118
}, [object Object] {
x: 176,
y: 183
}]
[[object Object] {
x: 176,
y: 183
}, [object Object] {
x: 276,
y: 239
}]
[[object Object] {
x: 276,
y: 239
}, [object Object] {
x: 341,
y: 90
}]
[[object Object] {
x: 341,
y: 90
}, [object Object] {
x: 140,
y: 99
}]
[[object Object] {
x: 140,
y: 99
}, [object Object] {
x: 253,
y: 335
}]
*/
`,
externalLink: {
platform: 'JSBin',
url: 'http://jsbin.com/cenuwip/6/embed?js,console,output'
}
}
],
relatedOperators: [
'buffer',
'bufferTime',
'bufferToggle',
'bufferWhen',
'pairwise',
'windowCount'
]
};