0

I want to subtract 2 observable numbers

this.num1:Observable<number>
this.num2:Observable<number>
this.num3:Observable<number>

this.num1 = this.store.select(getNum1Count);
this.num2 = this.store.select(getNum2Count);
// this.num3 = difference of this.num1 and this.num2 

in RXJS5 I was doing the below command

 this.num3 = Observable.combineLatest(this.num1,this.num2,(c1,c2)=> Math.abs(c1 - c2));

But in RXJS6, combineLatest is deprecated: Deprecated in favor of static combineLatest as shown here

How do we make this to work in RXJS 6?

On trying the RXJS6 format of combineLatest,

combineLatest(this.num3,this.num2, this.num1, (c1,c2) =>  Math.abs(c1 - c2 )),filter(x => x !== NaN);

I get an error The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type.

prabhat gundepalli
  • 907
  • 3
  • 15
  • 39
  • 1
    Only result selectors are deprecated, see https://github.com/ReactiveX/rxjs/blob/master/docs_app/content/guide/v6/migration.md#result-selectors-removed-or-deprecated – martin Jun 12 '18 at 19:51
  • 1
    just use `combineLatest` directly: `combineLatest(this.num1,this.num2,(c1,c2)=> Math.abs(c1 - c2));` – Chau Tran Jun 12 '18 at 20:01

1 Answers1

1

I was able to get it to work with help ( via gitter @Dorus and @GuillaumeUnice )

this.num3 = this.num1.pipe(combineLatest(this.num2),map(([n1,n2]) =>  Math.abs(n1 - n2))); 

Observation: As a developer it is weird when just a simple arithmetic operation is this complicated.

prabhat gundepalli
  • 907
  • 3
  • 15
  • 39