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

Commit e5c99b0

Browse files
docs(operators): add documentation for sample
Close #95
1 parent 8804ed5 commit e5c99b0

File tree

1 file changed

+52
-2
lines changed

1 file changed

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

33
export const sample: OperatorDoc = {
4-
'name': 'sample',
5-
'operatorType': 'filtering'
4+
name: 'sample',
5+
operatorType: 'filtering',
6+
signature: `public sample(notifier: Observable<any>): Observable<T>`,
7+
parameters: [
8+
{
9+
name: 'notifier',
10+
type: 'Observable<any>',
11+
attribute: '',
12+
description: 'The Observable to use for sampling the source Observable.'
13+
}
14+
],
15+
marbleUrl: 'http://reactivex.io/rxjs/img/sample.png',
16+
shortDescription: {
17+
description:
18+
'Emits the most recently emitted value from the source Observable whenever another Observable, the notifier, emits.',
19+
extras: [
20+
{
21+
type: 'Tip',
22+
text: `It's like sampleTime, but samples whenever the notifier Observable emits something.`
23+
}
24+
]
25+
},
26+
walkthrough: {
27+
description: `
28+
<p>
29+
Whenever the notifier Observable emits a value or completes,
30+
sample looks at the source Observable and emits whichever value it has most recently emitted since the previous sampling,
31+
unless the source has not emitted anything since the previous sampling.
32+
</p>
33+
<p>
34+
The notifier is subscribed to as soon as the output Observable is subscribed.
35+
</p>
36+
`
37+
},
38+
examples: [
39+
{
40+
name: 'On every click, sample the value from source every 2 seconds',
41+
code: `
42+
//emit value every 1s
43+
const source = Rx.Observable.interval(1000);
44+
//sample last emitted value from source every 2s
45+
const example = source.sample(Rx.Observable.interval(2000));
46+
//output: 2..4..6..8..
47+
const subscribe = example.subscribe(val => console.log(val));
48+
`,
49+
externalLink: {
50+
platform: 'JSBin',
51+
url: 'http://jsbin.com/gemebopifu/1/embed?js,console'
52+
}
53+
}
54+
],
55+
relatedOperators: ['audit', 'debounce', 'sampleTime', 'throttle']
656
};

0 commit comments

Comments
 (0)