Home > Mobile >  How to skip circual dependency in rxjs logic?
How to skip circual dependency in rxjs logic?

Time:09-22

There is a drawLine$ = new Subject<boolean>() subject into which I pass the value returned from the server.

This value drawLine$ is displayed in interface and user can change it: drawLine$.next(input.value)

And there is combineLatest ([drawLine $, ...]) which listens for the latest changes and sends it to the server for saving (autosave).

Problem is when I get data from server and pass it to drawLine$.next(input.value) it changes data in interface and calls again combineLatest ([drawLine $, ...] to send updation to server. I dont need it, because I got this data from server.

CodePudding user response:

Add this to your combinelatest:


combineLatest ([drawLine $, ...])
  .pipe(distinctUntilChanged())

If previous value is the same, distinctUntilChanged is not going to allow to pass to the following code (not pass to send the latest changes to the server for saving (autosave)).

More info about distinctUntilChanged HERE

  • Related