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

Commit e32b89a

Browse files
author
Diedrik De Mits
committed
docs(operators): Add documentation for bufferToggle
Add documentation for bufferToggle to close #112
1 parent 3535dce commit e32b89a

File tree

2 files changed

+91
-3
lines changed

2 files changed

+91
-3
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
"zone.js": "0.8.14"
4949
},
5050
"devDependencies": {
51-
"@angular/cli": "1.6.0",
51+
"@angular/cli": "1.6.5",
5252
"@angular/compiler-cli": "5.1.1",
5353
"@angular/language-service": "5.1.1",
5454
"@angular/service-worker": "5.1.1",
Lines changed: 90 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,94 @@
11
import { OperatorDoc } from '../operator.model';
22

33
export const bufferToggle: OperatorDoc = {
4-
'name': 'bufferToggle',
5-
'operatorType': 'transformation'
4+
name: 'bufferToggle',
5+
operatorType: 'transformation',
6+
signature: `bufferToggle(
7+
openings: SubscribableOrPromise<O>,
8+
closingSelector: (value: O) => SubscribableOrPromise): Observable<T[]>`,
9+
parameters: [
10+
{
11+
name: 'openings',
12+
type: 'SubscribableOrPromise<O>',
13+
attribute: '',
14+
description: `A Subscribable or Promise of notifications to start new buffers.`
15+
},
16+
{
17+
name: 'closingSelector',
18+
type: '(value: O) => SubscribableOrPromise',
19+
attribute: '',
20+
description: `A function that takes the value emitted by the openings observable
21+
and returns a Subscribable or Promise, which, when it emits, signals that the associated buffer should be emitted and cleared.`
22+
}
23+
],
24+
marbleUrl: 'http://reactivex.io/rxjs/img/bufferToggle.png',
25+
shortDescription: {
26+
description: `
27+
Buffers the source Observable values starting from an emission from <span class="markdown-code">openings</span>
28+
and ending when the output of <span class="markdown-code">closingSelector</span> emits.
29+
<span class="informal">
30+
Collects values from the past as an array. Starts collecting only when <span class="markdown-code">openings</span> emits,
31+
and calls the <span class="markdown-code">closingSelector</span> function
32+
to get an Observable that tells when to close the buffer.</span>`
33+
},
34+
walkthrough: {
35+
description: `
36+
Buffers values from the source by opening the buffer via signals from an Observable
37+
provided to <span class="markdown-code">openings</span>,
38+
and closing and sending the buffers when a Subscribable or Promise
39+
returned by the <span class="markdown-code">closingSelector</span> function emits.
40+
`
41+
},
42+
examples: [
43+
{
44+
name: 'Every other second, emit the click events from the next 500ms',
45+
code: `
46+
import { fromEvent } from 'rxjs/observable/fromEvent';
47+
import { interval } from 'rxjs/observable/interval';
48+
import { empty } from 'rxjs/observable/empty';
49+
import { map, bufferToggle } from 'rxjs/operators';
50+
51+
const clicks$ = fromEvent(document, 'click');
52+
const openings$ = interval(1000);
53+
const buffered$ = clicks$.pipe(
54+
map(e => {return {X: e.clientX, Y: e.clientY};}),
55+
bufferToggle(openings$, i => i % 2 ? interval(500) : empty())
56+
);
57+
buffered$.subscribe(x => console.log(x));
58+
`,
59+
externalLink: {
60+
platform: 'JSBin',
61+
url: 'http://jsbin.com/nuriyod/1/embed?js,console,output'
62+
}
63+
},
64+
{
65+
name:
66+
'Start buffering all the click events when you press the "S" key and close the buffer when you press the "E" key',
67+
code: `
68+
import { fromEvent } from 'rxjs/observable/fromEvent';
69+
import { filter, map, bufferToggle } from 'rxjs/operators';
70+
71+
const clicks$ = fromEvent(document, 'click');
72+
const keyUp$ = fromEvent(document,'keyup');
73+
const openings$ = keyUp$.pipe(filter(e => e.key === 's'));
74+
const closing$ = keyUp$.pipe(filter(e => e.key === 'e'));
75+
const buffered$ = clicks$.pipe(
76+
map(e => {return {X: e.clientX, Y: e.clientY};}),
77+
bufferToggle(openings$, _ => closing$)
78+
);
79+
buffered$.subscribe(x => console.log(x));
80+
`,
81+
externalLink: {
82+
platform: 'JSBin',
83+
url: 'http://jsbin.com/vurobel/8/embed?js,console,output'
84+
}
85+
}
86+
],
87+
relatedOperators: [
88+
'buffer',
89+
'bufferCount',
90+
'bufferTime',
91+
'bufferWhen',
92+
'windowToggle'
93+
]
694
};

0 commit comments

Comments
 (0)