The following code it's causing me a Observable.combineLatest is not a function
using RxJS 5.0:
let Observable = require('rxjs/Observable.js').Observable;
import 'rxjs/add/operator/combineLatest';
Observable
.combineLatest([player, spaceShip], (shotEvents, spaceShip) => ({
x: spaceShip ? spaceShip.x : board.canvas.width / 2,
timestamp: shotEvents.timestamp
}))
All other Observables are able to be resolved, the only function not being resolved is my combineLatest
. I tried observables/combineLatest
just for the sake of trying to no avail.
I'm compiling everything using webpack
and babel
, and the code is able to resolve scan
, range
, interval
, map
, and some others. Even flatMap
using import 'rxjs/add/operator/mergeMap';
worked.
But not combineLatest
So if anyone has a working example it would be deeply appreciated. Couldn't find anything else in the docs besides a unit test that is basically the same thing (an array of observables and a function).
On RxJs 5.5 use the following:
import { combineLatest } from 'rxjs/observable/combineLatest'
Moving forward (RxJs 6) use the following:
import { combineLatest } from 'rxjs'
combineLatest allows to merge several streams by taking the most recent value from each input observable and emitting those values to the observer as a combined output (usually as an array).
forkJoin - When all observables complete, emit the last emitted value from each. combineLatest - When any observable emits a value, emit the latest value from each.
When combineLatest subscribes to its sources, it prefetches 128 elements by default from them. This means that your first source will run to completion synchronously and the second subscription doesn't even happen until that completion.
I think #1722 is the relevant GitHub issue here.
I'm on a project using [email protected]
, [email protected]
, and [email protected]
. The following works for me:
import { Observable } from 'rxjs/Observable'; import 'rxjs/add/observable/combineLatest'; Observable.combineLatest( source1, source2 ).subscribe(sink);
To me this seems like a bug related to this issue.
Two potential workarounds:
import 'rxjs/add/operator/combineLatest';
, use import rxjs/rx
. This will register all operators (including combineLatest
) to Observable
.let Observable = require('rxjs/Observable.js').Observable;
Observable.prototype.combineLatest = require('rxjs/add/operator/combineLatest');
I'm on RXJS 5.5.6, to import combineLatest
for direct use (not as an operator) I had to use:
import {combineLatest} from 'rxjs/observable/combineLatest'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With