-
Notifications
You must be signed in to change notification settings - Fork 62
docs(operators): add documentation for sample & sampleTime #207
base: master
Are you sure you want to change the base?
Changes from 3 commits
cfbe5be
cc7666c
cdee0d0
5072a36
17e6cb8
2865cb3
4c80ee7
ad3cce0
c442d6f
829ac13
5dfd268
2b814f3
e81780c
0548cc6
7c09379
abcfc64
1a7cd49
7c69716
91f9546
c43c502
4160552
82e67e4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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.` | ||
} | ||
] | ||
}, | ||
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' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use embedded instead of edit. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oops! Yeah of course. |
||
} | ||
} | ||
], | ||
relatedOperators: ['audit', 'debounce', 'sampleTime', 'throttle'], | ||
additionalResources: [] | ||
}; |
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>', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add expected output There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here |
||
} | ||
} | ||
], | ||
relatedOperators: [ | ||
'auditTime', | ||
'debounceTime', | ||
'delay', | ||
'sample', | ||
'throttleTime' | ||
], | ||
additionalResources: [] | ||
}; |
There was a problem hiding this comment.
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
?There was a problem hiding this comment.
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.