lodash debounce cancel() 不停止 debounce 执行

lodash debounce cancel() not stopping the debounce execution

我编写了一个 angular 应用程序,我在其中对每个 modelChange 事件进行了 http 调用。我用过 lodash _.debounce()。问题是我无法在第一次成功执行 debounce 后取消这些调用。

  modelChangeEvent(item):void {
   const _this = this;
   let debounceObj = _.debounce(function(){
     _this.makeHttpCall(item);
     debounceObj.cancel();
    },600);
  debounceObj();
  }

https://lodash.com/docs/4.17.15#debounce

使用 Rxjs debounceTime()distinctUntilChanged()

实现
detectInput:any = new Subject();

ngOnInit(){
  this.detectInput.pipe(debounceTime(400),distinctUntilChanged()).subscribe(value=>{
    this.makeHttpCall(value)
  })
}

modelChangeEvent(item):void {
 this.detectInput.next(item);
}