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

docs(operators): add documentation for sample & sampleTime #207

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
cfbe5be
docs(operators): add documentation for sample
hardikpthv Dec 14, 2017
cc7666c
fix(operators): add markdown code to highlight keyword and replace va…
hardikpthv Dec 14, 2017
cdee0d0
docs(operators): add documentation for sampleTime
hardikpthv Dec 14, 2017
5072a36
Merge branch 'master' into iss-192
sumitarora Dec 15, 2017
17e6cb8
fix(operators): update code snippets
hardikpthv Dec 16, 2017
2865cb3
fix(operators): add link to existing operator
hardikpthv Dec 16, 2017
4c80ee7
Merge branch 'master' into iss-192
hardikpthv Dec 16, 2017
ad3cce0
Merge branch 'master' into iss-192
hardikpthv Dec 30, 2017
c442d6f
fix(operators): add link to existing operator and markdown to keywords
hardikpthv Dec 30, 2017
829ac13
Merge branch 'master' into iss-192
hardikpthv Jan 7, 2018
5dfd268
Merge branch 'master' into iss-192
hardikpthv Jan 9, 2018
2b814f3
Merge branch 'master' into iss-192
hardikpthv Jan 11, 2018
e81780c
Merge branch 'master' into iss-192
hardikpthv Jan 14, 2018
0548cc6
Merge branch 'master' into iss-192
hardikpthv Jan 27, 2018
7c09379
Merge branch 'master' into iss-192
hardikpthv Feb 5, 2018
abcfc64
Merge branch 'master' into iss-192
hardikpthv Feb 6, 2018
1a7cd49
Merge branch 'master' into iss-192
hardikpthv Mar 1, 2018
7c69716
Merge branch 'master' into iss-192
sumitarora Mar 10, 2018
91f9546
Merge branch 'master' into iss-192
hardikpthv Apr 1, 2018
c43c502
fix(operators): update code snippet
hardikpthv Apr 1, 2018
4160552
fix(operators): remove generic
hardikpthv Apr 1, 2018
82e67e4
Merge branch 'master' into iss-192
hardikpthv Apr 23, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/operator-docs/filtering/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { first } from './first';
import { ignoreElements } from './ignoreElements';
import { last } from './last';
import { sample } from './sample';
import { sampleTime } from './sampleTime';
import { single } from './single';
import { skip } from './skip';
import { skipUntil } from './skipUntil';
Expand All @@ -25,6 +26,7 @@ export const FILTERING_OPERATORS = [
ignoreElements,
last,
sample,
sampleTime,
single,
skip,
skipUntil,
Expand Down
54 changes: 52 additions & 2 deletions src/operator-docs/filtering/sample.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,56 @@
import { OperatorDoc } from '../operator.model';

export const sample: OperatorDoc = {
'name': 'sample',
'operatorType': 'filtering'
name: 'sample',
operatorType: 'filtering',
signature: 'public sample(notifier: Observable<any>): Observable<T>',
marbleUrl: 'http://reactivex.io/rxjs/img/sample.png',
parameters: [
{
name: 'notifier',
type: 'Observable<any>',
attribute: '',
description: `The Observable to use for sampling the source Observable.`
}
],
shortDescription: {
description: `
Emits the most recently emitted value from the source Observable
whenever another Observable, the <span class="markdown-code">notifier</span>, emits.
`,
extras: [
{
type: 'Tip',
text: `It's like sampleTime, but samples whenever the notifier Observable emits something.`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a link here to sampleTime?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, i will add it.

}
]
},
walkthrough: {
description: `
<p>
Whenever the <span class="markdown-code">notifier</span> Observable emits a value or completes,
<span class="markdown-code">sample</span> looks at the source Observable and emits whichever value
it has most recently emitted since the previous sampling,
unless the source has not emitted anything since the previous sampling.
The <span class="markdown-code">notifier</span> is subscribed to as soon as the output Observable is subscribed.
</p>
`
},
examples: [
{
name: 'On every click, sample the most recent "seconds" timer',
code: `
const seconds = Rx.Observable.interval(1000);
const clicks = Rx.Observable.fromEvent(document, 'click');
const result = seconds.sample(clicks);
result.subscribe(x => console.log(x))
`,
externalLink: {
platform: 'JSBin',
url: 'http://jsbin.com/xapiviz/edit?js,console,output'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use embedded instead of edit.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops! Yeah of course.

}
}
],
relatedOperators: ['audit', 'debounce', 'sampleTime', 'throttle'],
additionalResources: []
};
66 changes: 66 additions & 0 deletions src/operator-docs/filtering/sampleTime.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { OperatorDoc } from '../operator.model';

export const sampleTime: OperatorDoc = {
name: 'sampleTime',
operatorType: 'filtering',
signature:
'public sampleTime(period: number, scheduler: Scheduler): Observable<T>',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove generic

marbleUrl: 'http://reactivex.io/rxjs/img/sampleTime.png',
parameters: [
{
name: 'period',
type: 'number',
attribute: '',
description: `The sampling period expressed in milliseconds or the time unit determined internally by the optional scheduler.`
},
{
name: 'scheduler',
type: 'Scheduler',
attribute: 'optional default: async',
description: `The IScheduler to use for managing the timers that handle the sampling.`
}
],
shortDescription: {
description: `Emits the most recently emitted value from the source Observable within periodic time intervals.`,
extras: [
{
type: 'Tip',
text: `Samples the source Observable at periodic time intervals, emitting what it samples.`
}
]
},
walkthrough: {
description: `
<p>
<span class="markdown-code">sampleTime</span> periodically looks at the source
Observable and emits whichever value it has most recently emitted since the previous
sampling, unless the source has not emitted anything since the previous sampling.
The sampling happens periodically in time every <span class="markdown-code">period</span>
milliseconds (or the time unit defined by the optional <span class="markdown-code">scheduler</span> argument).
The sampling starts as soon as the output Observable is subscribed.
</p>
`
},
examples: [
{
name: 'Every second, emit the most recent click at most once',
code: `
const clicks = Rx.Observable.fromEvent(document, 'click');
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update it to ES6 imports

const result = clicks.sampleTime(1000);
result.subscribe(x => console.log(x));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add expected output

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hardikpthv I'm a bit confused :D will you take care of your comments in this pr :D

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure @jwo719 It is for my reference :D

`,
externalLink: {
platform: 'JSBin',
url: 'http://jsbin.com/hohulon/edit?js,console,output'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

}
}
],
relatedOperators: [
'auditTime',
'debounceTime',
'delay',
'sample',
'throttleTime'
],
additionalResources: []
};