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

Commit 92b02fb

Browse files
authored
Merge branch 'master' into feat/stackblitz
2 parents 57a8909 + 621c41d commit 92b02fb

File tree

4 files changed

+294
-6
lines changed

4 files changed

+294
-6
lines changed

CNAME

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
rxjsdocs.com
Lines changed: 142 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,146 @@
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,
8+
closingSelector: (value) => SubscribableOrPromise): Observable`,
9+
parameters: [
10+
{
11+
name: 'openings',
12+
type: 'SubscribableOrPromise',
13+
attribute: '',
14+
description: `A Subscribable or Promise of notifications to start new buffers.`
15+
},
16+
{
17+
name: 'closingSelector',
18+
type: '(value) => 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 { bufferToggle } from 'rxjs/operators';
50+
51+
const clicks = fromEvent(document, 'click', e => ({x: e.clientX, y: e.clientY}));
52+
const openings = interval(1000);
53+
const buffered = clicks.pipe(
54+
bufferToggle(openings, i => i % 2 ? interval(500) : empty())
55+
);
56+
buffered.subscribe(x => console.log(x));
57+
/*
58+
Expected console output:
59+
60+
[]
61+
62+
[[object Object] {
63+
x: 156,
64+
y: 165
65+
}, [object Object] {
66+
x: 156,
67+
y: 165
68+
}, [object Object] {
69+
x: 156,
70+
y: 165
71+
}]
72+
73+
[]
74+
75+
[]
76+
*/
77+
`,
78+
externalLink: {
79+
platform: 'JSBin',
80+
url: 'http://jsbin.com/nuriyod/6/embed?js,console,output'
81+
}
82+
},
83+
{
84+
name:
85+
'Start buffering all the click events when you press the "S" key and close the buffer when you press the "E" key',
86+
code: `
87+
import { fromEvent } from 'rxjs/observable/fromEvent';
88+
import { filter, bufferToggle } from 'rxjs/operators';
89+
90+
const clicks = fromEvent(document, 'click', e => ({x: e.clientX, y: e.clientY}));
91+
const keyUp = fromEvent(document,'keyup');
92+
const openings = keyUp.pipe(filter(e => e.key === 's'));
93+
const closing = keyUp.pipe(filter(e => e.key === 'e'));
94+
const buffered = clicks.pipe(
95+
bufferToggle(openings, _ => closing)
96+
);
97+
buffered.subscribe(x => console.log(x));
98+
99+
/*
100+
Expected console output:
101+
102+
[[object Object] {
103+
x: 147,
104+
y: 135
105+
}, [object Object] {
106+
x: 147,
107+
y: 135
108+
}, [object Object] {
109+
x: 144,
110+
y: 135
111+
}, [object Object] {
112+
x: 144,
113+
y: 135
114+
}, [object Object] {
115+
x: 144,
116+
y: 135
117+
}]
118+
119+
[[object Object] {
120+
x: 144,
121+
y: 135
122+
}, [object Object] {
123+
x: 144,
124+
y: 135
125+
}]
126+
127+
[[object Object] {
128+
x: 143,
129+
y: 136
130+
}]
131+
*/
132+
`,
133+
externalLink: {
134+
platform: 'JSBin',
135+
url: 'http://jsbin.com/vurobel/12/embed?js,console,output'
136+
}
137+
}
138+
],
139+
relatedOperators: [
140+
'buffer',
141+
'bufferCount',
142+
'bufferTime',
143+
'bufferWhen',
144+
'windowToggle'
145+
]
6146
};
Lines changed: 92 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,96 @@
11
import { OperatorDoc } from '../operator.model';
22

33
export const mergeMap: OperatorDoc = {
4-
'name': 'mergeMap',
5-
'operatorType': 'transformation'
4+
name: 'mergeMap',
5+
operatorType: 'transformation',
6+
signature:
7+
'public mergeMap(project: Function, resultSelector?: Function, concurrent?: number): Observable',
8+
useInteractiveMarbles: true,
9+
parameters: [
10+
{
11+
name: 'project',
12+
type: '(value: T, index: number) => ObservableInput',
13+
attribute: '',
14+
description: `A function that, when applied to an item emitted by the source Observable, returns
15+
an Observable.`
16+
},
17+
{
18+
name: 'resultSelector',
19+
type:
20+
'(outerValue: T, innerValue: I, outerIndex: number, innerIndex: number) => any',
21+
attribute: 'optional',
22+
description: `A function to produce the value on the output Observable based on the values and the indices
23+
of the source (outer) emission and the inner Observable emission. The arguments passed to this function are:
24+
'outerValue': the value that came from the source,
25+
'innerValue': the value that came from the projected Observable,
26+
'outerIndex': the "index" of the value that came from the source,
27+
'innerIndex': the "index" of the value from the projected Observable.`
28+
},
29+
{
30+
name: 'concurrent',
31+
type: 'number',
32+
attribute: 'optional',
33+
description: `Maximum number of input Observables being subscribed to concurrently.`
34+
}
35+
],
36+
marbleUrl: 'http://reactivex.io/rxjs/img/mergeMap.png',
37+
shortDescription: {
38+
description: `
39+
Projects each source value to an Observable which is merged in the output Observable.
40+
`,
41+
extras: []
42+
},
43+
walkthrough: {
44+
description: `
45+
<p>
46+
Returns an Observable that emits items based on applying a function that you supply
47+
to each item emitted by the source Observable, where that function returns an Observable,
48+
and then merging those resulting Observables and emitting the results of this merger.
49+
</p>
50+
`
51+
},
52+
examples: [
53+
{
54+
name:
55+
'Map and flatten each letter to an Observable ticking every 1 second',
56+
code: `
57+
import { of } from 'rxjs/observable/of';
58+
import { interval } from 'rxjs/observable/interval';
59+
import { mergeMap, map } from 'rxjs/operators';
60+
61+
const letters = of('a', 'b', 'c');
62+
const result = letters.pipe(
63+
mergeMap(x => {
64+
return interval(1000).pipe(map(i => x+i));
65+
})
66+
);
67+
result.subscribe(x => console.log(x));
68+
69+
// Output
70+
"a0"
71+
"b0"
72+
"c0"
73+
"a1"
74+
"b1"
75+
"c1"
76+
"a2"
77+
"b2"
78+
"c2"
79+
`,
80+
externalLink: {
81+
platform: 'JSBin',
82+
url: 'http://jsbin.com/pekelowibe/embed?js,console'
83+
}
84+
}
85+
],
86+
relatedOperators: [
87+
'concatMap',
88+
'exhaustmap',
89+
'merge',
90+
'mergeAll',
91+
'mergeMapTo',
92+
'mergeScan',
93+
'switchMap'
94+
],
95+
additionalResources: []
696
};

src/operator-docs/utility/let.ts

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

33
export const letOperator: OperatorDoc = {
4-
'name': 'let',
5-
'operatorType': 'utility'
4+
name: 'let',
5+
operatorType: 'utility',
6+
signature: 'public let(fun: function): Observable,',
7+
parameters: [
8+
{
9+
name: 'fun',
10+
type: 'function',
11+
attribute: '',
12+
description: `Selector function which can use the source sequence
13+
as many times as needed, without sharing subscriptions to the source sequence.`
14+
}
15+
],
16+
shortDescription: {
17+
description: `Returns an observable sequence that is the result of invoking the selector on the source sequence,
18+
without sharing subscriptions. This operator allows for a fluent style of writing queries that use the same
19+
sequence multiple times. There is an alias of letBind for browsers older than IE 9.`
20+
},
21+
additionalResources: [
22+
{
23+
url: 'https://www.learnrxjs.io/operators/utility/let.html',
24+
description: 'several examples of using the let operator',
25+
author: 'btroncone'
26+
}
27+
],
28+
examples: [
29+
{
30+
name: 'calls concat as part of a pipeline',
31+
code: `
32+
import { range } from 'rxjs/observable/range';
33+
34+
const obs = range(1, 3);
35+
36+
const source = obs.let((o) => o.concat(o));
37+
38+
const subscription = source.subscribe(
39+
(x) => {
40+
console.log('Next: ' + x);
41+
},
42+
(err) => {
43+
console.log('Error: ' + err);
44+
},
45+
() => {
46+
console.log('Completed');
47+
});
48+
49+
// => Next: 1
50+
// => Next: 2
51+
// => Next: 3
52+
// => Next: 1
53+
// => Next: 2
54+
// => Next: 3
55+
// => Completed
56+
`,
57+
externalLink: {
58+
platform: 'JSBin',
59+
url: 'http://jsbin.com/giwanupiqu/embed?html,js,console'
60+
}
61+
}
62+
]
663
};

0 commit comments

Comments
 (0)