rxjs

'of' vs 'from' operator


Is the only difference between Observable.of and Observable.from the arguments format? Like the Function.prototype.call and Function.prototype.apply?

Observable.of(1,2,3).subscribe(() => {})
Observable.from([1,2,3]).subscribe(() => {})

Solution

  • Not quite. When passing an array to Observable.from, the only difference between it and Observable.of is the way the arguments are passed.

    However, Observable.from will accept an argument that is

    a subscribable object, a Promise, an Observable-like, an Array, an iterable or an array-like object to be converted

    There is no similar behaviour for Observable.of - which always accepts only values and performs no conversion.