Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/107.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Rxjs 使用去BounceTime时,可观察到的延迟时间有多长?_Rxjs - Fatal编程技术网

Rxjs 使用去BounceTime时,可观察到的延迟时间有多长?

Rxjs 使用去BounceTime时,可观察到的延迟时间有多长?,rxjs,Rxjs,在此示例中:从第一个间隔到从debounceTime运算符发出值的时间延迟为4秒 有没有办法知道/能够记录去抖动的窗口?是的,您需要时间间隔操作符 把它放在去BounceTime之后 更新: 好的,我明白了。您肯定需要一个自定义运算符。试试这个 import { fromEvent, OperatorFunction } from 'rxjs'; import { debounceTime, tap, map } from 'rxjs/operators'; const clicks = fr

在此示例中:从第一个间隔到从debounceTime运算符发出值的时间延迟为4秒


有没有办法知道/能够记录去抖动的窗口?

是的,您需要时间间隔操作符

把它放在去BounceTime之后

更新:

好的,我明白了。您肯定需要一个自定义运算符。试试这个

import { fromEvent, OperatorFunction } from 'rxjs';
import { debounceTime, tap, map } from 'rxjs/operators';

const clicks = fromEvent(document, 'click');
const result = clicks.pipe(debounceTimeWithIntervalTracking(1000));
result.subscribe(x => console.log(x));

function debounceTimeWithIntervalTracking<T>(time: number): OperatorFunction<T, { value: T, delayedFor: number }> {
  let startedTime = new Date().getTime();
  let restart = true;
  return src$ => src$.pipe(
    tap(() => {
      if (restart) {
        startedTime = new Date().getTime();
      }
      restart = false;
    }),
    debounceTime(time),
    map(value => {
      const delayedFor = new Date().getTime() - startedTime;
      restart = true;
      return { value, delayedFor };
    })
  )
}
从'rxjs'导入{fromEvent,OperatorFunction};
从“rxjs/operators”导入{debounceTime,tap,map};
const clicks=fromEvent(文档“click”);
const result=clicks.pipe(间隔跟踪(1000))的去BounceTime;
subscribe(x=>console.log(x));
函数debounceTimeWithIntervalTracking(时间:编号):运算符函数{
让startedTime=newdate().getTime();
让restart=true;
返回src$=>src$.pipe(
点击(()=>{
如果(重新启动){
startedTime=新日期().getTime();
}
重新启动=错误;
}),
去BounceTime(时间),
映射(值=>{
const delayedFor=new Date().getTime()-startedTime;
重启=真;
返回{value,delayedFor};
})
)
}

是的,您需要时间间隔运算符

把它放在去BounceTime之后

更新:

好的,我明白了。您肯定需要一个自定义运算符。试试这个

import { fromEvent, OperatorFunction } from 'rxjs';
import { debounceTime, tap, map } from 'rxjs/operators';

const clicks = fromEvent(document, 'click');
const result = clicks.pipe(debounceTimeWithIntervalTracking(1000));
result.subscribe(x => console.log(x));

function debounceTimeWithIntervalTracking<T>(time: number): OperatorFunction<T, { value: T, delayedFor: number }> {
  let startedTime = new Date().getTime();
  let restart = true;
  return src$ => src$.pipe(
    tap(() => {
      if (restart) {
        startedTime = new Date().getTime();
      }
      restart = false;
    }),
    debounceTime(time),
    map(value => {
      const delayedFor = new Date().getTime() - startedTime;
      restart = true;
      return { value, delayedFor };
    })
  )
}
从'rxjs'导入{fromEvent,OperatorFunction};
从“rxjs/operators”导入{debounceTime,tap,map};
const clicks=fromEvent(文档“click”);
const result=clicks.pipe(间隔跟踪(1000))的去BounceTime;
subscribe(x=>console.log(x));
函数debounceTimeWithIntervalTracking(时间:编号):运算符函数{
让startedTime=newdate().getTime();
让restart=true;
返回src$=>src$.pipe(
点击(()=>{
如果(重新启动){
startedTime=新日期().getTime();
}
重新启动=错误;
}),
去BounceTime(时间),
映射(值=>{
const delayedFor=new Date().getTime()-startedTime;
重启=真;
返回{value,delayedFor};
})
)
}

我不确定这正是我想要的。这将给我两次发射之间的时间,但不是去抖动的时间窗。然而。。。如果我把它和开关映射连接起来。。。我可能会安排一个操作员来测量……不,那不行。。。我需要一个类似“去盎司分组”的东西,并比较初始时间和最终时间。我不确定这正是我想要的。这将给我两次发射之间的时间,但不是去抖动的时间窗。然而。。。如果我把它和开关映射连接起来。。。我可能会安排一个操作员来测量……不,那不行。。。我需要一个类似于“去盎司分组”的东西,并比较初始时间戳和最终时间戳