Skip to content
This repository was archived by the owner on Oct 1, 2018. It is now read-only.

Commit 9bbff70

Browse files
Merge pull request #235 from DiedrikDM/docs-transformation-buffertime
docs(operators): add documentation for bufferTime
2 parents 6a90120 + ce87587 commit 9bbff70

File tree

1 file changed

+171
-2
lines changed

1 file changed

+171
-2
lines changed
Lines changed: 171 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,175 @@
11
import { OperatorDoc } from '../operator.model';
22

33
export const bufferTime: OperatorDoc = {
4-
'name': 'bufferTime',
5-
'operatorType': 'transformation'
4+
name: 'bufferTime',
5+
operatorType: 'transformation',
6+
signature: `bufferTime(
7+
bufferTimeSpan: number,
8+
bufferCreationInterval: number,
9+
maxBufferSize: number,
10+
scheduler: Scheduler): Observable`,
11+
parameters: [
12+
{
13+
name: 'bufferTimeSpan',
14+
type: 'number',
15+
attribute: '',
16+
description: `The amount of time (in milliseconds) to fill each buffer array.`
17+
},
18+
{
19+
name: 'bufferCreationInterval',
20+
type: 'number',
21+
attribute: 'optional',
22+
description: `The interval (in milliseconds) at which to start new buffers.`
23+
},
24+
{
25+
name: 'maxBufferSize',
26+
type: 'number',
27+
attribute: 'optional',
28+
description: `The maximum amount of items per buffer.`
29+
},
30+
{
31+
name: 'scheduler',
32+
type: 'Scheduler',
33+
attribute: `optional
34+
default: async`,
35+
description: `The scheduler on which to schedule the intervals that determine buffer boundaries.`
36+
}
37+
],
38+
marbleUrl: 'http://reactivex.io/rxjs/img/bufferTime.png',
39+
shortDescription: {
40+
description: `Buffers the source Observable values for a specific time period.
41+
42+
<span class="informal">Collects values from the past as an array, and emits those arrays periodically in time.</span>`
43+
},
44+
walkthrough: {
45+
description: `
46+
Buffers values from the source for a specific time duration <span class="markdown-code">bufferTimeSpan</span>.
47+
It emits and resets the buffer every <span class="markdown-code">bufferTimeSpan</span> milliseconds,
48+
unless the optional argument <span class="markdown-code">bufferCreationInterval</span> is given.
49+
If <span class="markdown-code">bufferCreationInterval</span> is given,
50+
this operator emits the buffered values and re-opens the buffer every <span class="markdown-code">bufferCreationInterval</span>
51+
milliseconds and closes (no further values are buffered) the buffer every
52+
<span class="markdown-code">bufferTimeSpan</span> milliseconds.
53+
When the optional argument <span class="markdown-code">maxBufferSize</span> is specified,
54+
the buffer will be closed either after <span class="markdown-code">bufferTimeSpan</span> milliseconds
55+
or when it contains <span class="markdown-code">maxBufferSize</span> elements.`
56+
},
57+
examples: [
58+
{
59+
name:
60+
'After every two and a half seconds, emit an array of the click events during that timeframe',
61+
code: `
62+
import { fromEvent } from 'rxjs/observable/fromEvent';
63+
import { bufferTime } from 'rxjs/operators';
64+
65+
const clicks = fromEvent(document, 'click', e => ({x: e.clientX, y: e.clientY}));
66+
const buffered = clicks.pipe(
67+
bufferTime(2500)
68+
);
69+
buffered.subscribe(x => console.log(x));
70+
71+
/*
72+
Example console output
73+
74+
[]
75+
76+
[[object Object] {
77+
x: 150,
78+
y: 139
79+
}, [object Object] {
80+
x: 150,
81+
y: 139
82+
}, [object Object] {
83+
x: 150,
84+
y: 139
85+
}, [object Object] {
86+
x: 150,
87+
y: 139
88+
}]
89+
90+
[[object Object] {
91+
x: 150,
92+
y: 139
93+
}]
94+
95+
[[object Object] {
96+
x: 150,
97+
y: 137
98+
}, [object Object] {
99+
x: 150,
100+
y: 137
101+
}]
102+
103+
[]
104+
*/
105+
`,
106+
externalLink: {
107+
platform: 'JSBin',
108+
url: 'http://jsbin.com/fuqewiy/7/embed?js,console,output'
109+
}
110+
},
111+
{
112+
name:
113+
'Every five seconds, emit the click events from a window of the last two seconds',
114+
code: `
115+
import { fromEvent } from 'rxjs/observable/fromEvent';
116+
import { bufferTime } from 'rxjs/operators';
117+
118+
const clicks = fromEvent(document, 'click', e => ({x: e.clientX, y: e.clientY}));
119+
const buffered = clicks.pipe(
120+
bufferTime(2000, 5000)
121+
);
122+
buffered.subscribe(x => console.log(x));
123+
124+
/*
125+
Example console output:
126+
127+
[]
128+
129+
[]
130+
131+
[[object Object] {
132+
x: 159,
133+
y: 140
134+
}, [object Object] {
135+
x: 159,
136+
y: 140
137+
}]
138+
139+
[[object Object] {
140+
x: 161,
141+
y: 140
142+
}, [object Object] {
143+
x: 161,
144+
y: 140
145+
}, [object Object] {
146+
x: 161,
147+
y: 140
148+
}, [object Object] {
149+
x: 161,
150+
y: 140
151+
}, [object Object] {
152+
x: 161,
153+
y: 140
154+
}, [object Object] {
155+
x: 161,
156+
y: 140
157+
}]
158+
159+
[]
160+
*/
161+
`,
162+
externalLink: {
163+
platform: 'JSBin',
164+
url: 'http://jsbin.com/xohupot/6/embed?js,console,output'
165+
}
166+
}
167+
],
168+
relatedOperators: [
169+
'buffer',
170+
'bufferCount',
171+
'bufferToggle',
172+
'bufferWhen',
173+
'windowTime'
174+
]
6175
};

0 commit comments

Comments
 (0)