油门时间运算符的config参数如何工作?(ThrottleConfig) [英] How does throttleTime operator's config parameter work? (ThrottleConfig)
问题描述
我已经阅读了 throttleTime文档,但是我没有得到完全操作.
I have read the throttleTime documentation, but I don't get the operator fully.
我知道 throttleTime(1000)
的工作方式.事件到达后,它将跳过所有后续事件1秒钟,然后再次开始此过程.
I know how throttleTime(1000)
works. After an event arrives it will skip all subsequent events for 1 second and then start this process again.
我很难理解的是 ThrottleConfig
的工作原理,这是运算符的第三个参数.
What I have trouble to understand is how exactly ThrottleConfig
works, which is the third parameter of the operator.
throttleTime<T>(
duration: number,
scheduler: SchedulerLike = async,
config: ThrottleConfig = defaultThrottleConfig): MonoTypeOperatorFunction<T>
前导
和 trailing
属性如何更改源Observable的功能?
How do leading
and trailing
properties change the functionality of the source Observable?
我已经阅读了许多文档,但是他们并没有清楚地解释这一点.
I have read many documentations but they don't clearly explain this.
所以有四个选项:
-
{开头:true,结尾:false}
:
默认选项,在接收事件后,将在指定的持续时间内跳过其他事件,然后重复执行. -
{开头:false,结尾:true}
:
??? -
{开头:false,结尾:false}
:
经过测试,Observable根本不发出任何东西. -
{前导:true,结尾:true}
:
???
推荐答案
throttleTime
将开始一个新的节气门间隔(不发射任何物品的时间段)当它收到一个新值并且尚未受到限制时.节气门间隔的长度由您提供的持续时间决定.
throttleTime
will start a new throttle interval (a time period in which no items will be emitted) when it receives a new value and isn't already throttled. The length of this throttle interval is determined by the duration you supply.
前导
和 trailing
指定是在油门时间间隔的开始还是结束时发射项目.
leading
and trailing
specify whether an item should be emitted at the beginning or end of a throttle interval.
前导:
发出在节气门间隔的开头开始新的节气门间隔的项目.
leading:
Emit the item that starts a new throttle interval at the beginning of the throttle interval.
跟踪:
在油门时间间隔结束时发出从源接收的最后一个项目.
trailing:
Emit the last item received from the source at the end of a throttle interval.
throttleTime(12 ticks, async, { leading: true, trailing: false })
source: --0--1-----2--3----4--5-6---7------------8-------9--------
throttle interval: --[~~~~~~~~~~~~]---[~~~~~~~~~~~~]--------[~~~~~~~~~~~~]---
output: --0----------------4---------------------8----------------
throttleTime(12 ticks, async, { leading: false, trailing: true })
source: --0--1-----2--3----4--5-6---7------------8-------9--------
throttle interval: --[~~~~~~~~~~~~]---[~~~~~~~~~~~~]--------[~~~~~~~~~~~~]---
output: ---------------3----------------7---------------------9---
throttleTime(12 ticks, async, { leading: true, trailing: true })
source: --0--1-----2--3----4--5-6---7------------8-------9--------
throttle interval: --[~~~~~~~~~~~~]---[~~~~~~~~~~~~]--------[~~~~~~~~~~~~]---
output: --0------------3---4------------7--------8------------9---
throttleTime(12 ticks, async, { leading: false, trailing: false })
source: --0--1-----2--3----4--5-6---7------------8-------9--------
throttle interval: --[~~~~~~~~~~~~]---[~~~~~~~~~~~~]--------[~~~~~~~~~~~~]---
output: ----------------------------------------------------------
这篇关于油门时间运算符的config参数如何工作?(ThrottleConfig)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!