Why would you ever call .call() on Observable functions?

后端 未结 3 494
慢半拍i
慢半拍i 2021-01-12 07:09

I am a relative beginner in Angular, and I am struggling to understand some source I am reading from the ng-bootstrap project. The source code can be found here.

I

3条回答
  •  孤独总比滥情好
    2021-01-12 07:30

    I suppose

    const inputValues$ = _do.call(this._valueChanges, value => {
      this._userInput = value;
      if (this.editable) {
        this._onChange(value);
      }
    }); 
    

    is equivalent to

    const inputValues$=this._valueChanges.do(value=>{
     this._userInput = value;
      if (this.editable) {
        this._onChange(value);
      }
    })
    

    In my opinion it's not an usual pattern(I think it is the same pattern but written in different fashion) for working with observable. _do() in the code is being used as standalone function take a callback as argument and required to be binded to the scope of the source Observable

    https://github.com/ReactiveX/rxjs/blob/master/src/operator/do.ts

提交回复
热议问题