|
1 | | -import { OperatorDoc } from '../operator.model'; |
| 1 | +import { OperatorDoc } from "../operator.model"; |
2 | 2 |
|
3 | 3 | export const debounceTime: OperatorDoc = { |
4 | | - 'name': 'debounceTime', |
5 | | - 'operatorType': 'filtering' |
| 4 | + name: "debounceTime", |
| 5 | + operatorType: "filtering", |
| 6 | + signature: |
| 7 | + "public debounceTime<T>(dueTime: number, scheduler: IScheduler = async): Observable", |
| 8 | + parameters: [ |
| 9 | + { |
| 10 | + name: "dueTime", |
| 11 | + type: "number", |
| 12 | + attribute: "mandatory", |
| 13 | + description: `The timeout duration in milliseconds |
| 14 | + (or the time unit determined internally by the optional scheduler) for the window of time required to |
| 15 | + wait for emission silence before emitting the most recent source value.` |
| 16 | + }, |
| 17 | + { |
| 18 | + name: "scheduler", |
| 19 | + type: "IScheduler", |
| 20 | + attribute: "optional", |
| 21 | + description: `The IScheduler to use for managing the timers that handle the timeout for each value.` |
| 22 | + } |
| 23 | + ], |
| 24 | + marbleUrl: "http://reactivex.io/rxjs/img/debounceTime.png", |
| 25 | + shortDescription: { |
| 26 | + description: ` |
| 27 | + Emits a value from the source Observable only after a particular time span has passed without another source emission. |
| 28 | + It's like <a class="markdown-code" href="href="/operators#delay">delay</a> |
| 29 | + , but passes only the most recent value from each burst of emissions.`, |
| 30 | + extras: [] |
| 31 | + }, |
| 32 | + walkthrough: { |
| 33 | + description: ` |
| 34 | + <p> |
| 35 | + <span class="markdown-code">debounceTime</span> delays values emitted by the source Observable, but drops |
| 36 | + previous pending delayed emissions if a new value arrives on the source |
| 37 | + Observable. This operator keeps track of the most recent value from the |
| 38 | + source Observable, and emits that only when <span class="markdown-code">dueTime</span> enough time has passed |
| 39 | + without any other value appearing on the source Observable. If a new value |
| 40 | + appears before <span class="markdown-code">dueTime</span> silence occurs, the previous value will be dropped |
| 41 | + and will not be emitted on the output Observable. |
| 42 | + </p> |
| 43 | + <p> |
| 44 | + This is a rate-limiting operator, because it is impossible for more than one |
| 45 | + value to be emitted in any time window of duration <span class="markdown-code">dueTime</span>, but it is also |
| 46 | + a delay-like operator since output emissions do not occur at the same time as |
| 47 | + they did on the source Observable. Optionally takes a <span class="markdown-code">IScheduler</span> for |
| 48 | + managing timers. |
| 49 | + </p> |
| 50 | + ` |
| 51 | + }, |
| 52 | + examples: [ |
| 53 | + { |
| 54 | + name: |
| 55 | + "Emit the most recent value after a burst of value changes over a defined time", |
| 56 | + code: ` |
| 57 | + const search = document.querySelector('#search'); |
| 58 | + const output = document.querySelector('#output'); |
| 59 | + const searchChange$ = Rx.Observable.fromEvent(search, 'keyup'); |
| 60 | +
|
| 61 | + searchChange$ |
| 62 | + .map(x => x.target.value) |
| 63 | + .debounceTime(500) |
| 64 | + .subscribe((search)=> output.textContent=search); |
| 65 | + `, |
| 66 | + externalLink: { |
| 67 | + platform: "JSBin", |
| 68 | + url: "http://jsbin.com/gapobakuwu/edit?js,output" |
| 69 | + } |
| 70 | + } |
| 71 | + ], |
| 72 | + relatedOperators: [ |
| 73 | + "auditTime", |
| 74 | + "debounce", |
| 75 | + "delay", |
| 76 | + "sampleTime", |
| 77 | + "throttleTime" |
| 78 | + ], |
| 79 | + additionalResources: [] |
6 | 80 | }; |
0 commit comments