Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

merge deprecation warning confusion

Tags:

rxjs

Using RXJS I have the following

      merge(this.optionValueChanged$, this.options.changes).subscribe(() => {
        this.selectionByValue(this.pValue)
      }),

now, on hover this return

@deprecated — use {@link scheduled} and {@link mergeAll} (e.g. `scheduled([ob1, ob2, ob3], scheduled).pipe(mergeAll())

but I read about scheduled, and it looks like it's not exactly doing what I want. Also, I can't figure out what those the scheduled inside the method scheduled stand for.

like image 596
Bobby Avatar asked Sep 03 '20 07:09

Bobby


3 Answers

Typescript selects the wrong overload. Only the overloads that accept SchedulerLike are deprecated.

Try to change the order of your parameters

merge(this.options.changes, this.optionValueChanged$)

Or wrap them in an array and spread

merge(...[this.optionValueChanged$, this.options.changes])
like image 130
frido Avatar answered Oct 13 '22 04:10

frido


Also ran into this, was solved when I explicitly defined the parameter types before passing into merge.

i.e.

const obs1: ObservableInput<any> = ...
const obs2: ObservableInput<any> = ...
return merge(obs1, obs2).pipe(...)

like image 22
jrhee17 Avatar answered Oct 13 '22 06:10

jrhee17


I agree, that is confusing. I always saw it as some kind of any in that way, that this is a placeholder for an observable which emits other observables.

Have a look on this example

const ob1 = of(1).pipe(delay(5000));
const ob2 = of(2).pipe(delay(1000));
const ob3 = of(3).pipe(delay(2000));

function schedule() {
  return of(ob1, ob2, ob3);
}

schedule().pipe(
  mergeAll(),
).subscribe(console.log);

It has the same functionality as merge, the 1 is printed last, because it is emitted last.

See stackblitz: https://stackblitz.com/edit/rxjs-z6t8yn?file=index.ts

like image 41
MoxxiManagarm Avatar answered Oct 13 '22 06:10

MoxxiManagarm