|
1 | 1 | import { OperatorDoc } from '../operator.model'; |
2 | 2 |
|
3 | 3 | export const throttle: OperatorDoc = { |
4 | | - 'name': 'throttle', |
5 | | - 'operatorType': 'filtering' |
| 4 | + name: 'throttle', |
| 5 | + operatorType: 'filtering', |
| 6 | + signature: |
| 7 | + 'public throttle(durationSelector: function(value: T): SubscribableOrPromise): Observable<T>', |
| 8 | + parameters: [ |
| 9 | + { |
| 10 | + name: 'durationSelector', |
| 11 | + type: 'function(value: T): SubscribableOrPromise', |
| 12 | + attribute: '', |
| 13 | + description: ` |
| 14 | + A function that receives a value from the source Observable, for computing the silencing duration for each source value, |
| 15 | + returned as an Observable or a Promise. |
| 16 | + ` |
| 17 | + } |
| 18 | + ], |
| 19 | + marbleUrl: 'http://reactivex.io/rxjs/img/throttle.png', |
| 20 | + shortDescription: { |
| 21 | + description: `Emits a value from the source Observable, then ignores subsequent source values for a duration |
| 22 | + determined by another Observable, then repeats this process.`, |
| 23 | + extras: [ |
| 24 | + { |
| 25 | + type: 'Tip', |
| 26 | + text: `It's like throttleTime, but the silencing duration is determined by a second Observable.` |
| 27 | + } |
| 28 | + ] |
| 29 | + }, |
| 30 | + walkthrough: { |
| 31 | + description: ` |
| 32 | + <p> |
| 33 | + <code>throttle</code> emits the source Observable values on the output Observable when its internal timer is disabled, |
| 34 | + and ignores source values when the timer is enabled. Initially, the timer is disabled. |
| 35 | + </p> |
| 36 | + <p> |
| 37 | + As soon as the first source value arrives, it is forwarded to the output Observable, |
| 38 | + and then the timer is enabled by calling the durationSelector function with the source value, |
| 39 | + which returns the "duration" Observable. |
| 40 | + </p> |
| 41 | + <p> |
| 42 | + When the duration Observable emits a value or completes, |
| 43 | + the timer is disabled, and this process repeats for the next source value. |
| 44 | + </p> |
| 45 | + ` |
| 46 | + }, |
| 47 | + examples: [ |
| 48 | + { |
| 49 | + name: |
| 50 | + 'Emit X position of mouse click at a rate of at most one click per second', |
| 51 | + code: ` |
| 52 | + const clicks = Rx.Observable.fromEvent(document, 'click'); |
| 53 | + const result = clicks.throttle(ev => Rx.Observable.interval(1000)); |
| 54 | + result.subscribe(x => console.log(x.clientX)); |
| 55 | + `, |
| 56 | + externalLink: { |
| 57 | + platform: 'JSBin', |
| 58 | + url: 'http://jsbin.com/wojifil/embed?js,console,output' |
| 59 | + } |
| 60 | + } |
| 61 | + ], |
| 62 | + relatedOperators: ['audit', 'debounce', 'delayWhen', 'sample', 'throttleTime'] |
6 | 63 | }; |
0 commit comments