angularfire icon indicating copy to clipboard operation
angularfire copied to clipboard

Invalid object with afDb.object.valueChanges in switchMap

Open jgan42 opened this issue 8 years ago • 4 comments

Version info

**Angular: ~6.0.0 **Firebase: 5.0.4 and 5.1.0 **AngularFire: ^5.0.0-rc.11 **Rxjs: 6.2.1

The observable returned by AngularFireDatabase can't be returned by switchMap operator's callback. I tried a few combinations of versions and I figured out that this bug is only produced with Firebase 5.0.4 and above.

I don't get this error with : Angular 6.0.0 to 6.0.6 Firebase 5.0.3 AngularFire 5.0.0-rc.9 to 5.0.0-rc.11 Rxjs 6.0.0 to 6.2.1

How to reproduce these conditions

Steps to set up and reproduce

-ng new -install Firebase and AngularFire

of(true).pipe(switchMap(() => this.afDb.object('anyRef').valueChanges())).subscribe()

Debug output

ERROR TypeError: You provided an invalid object where a stream was expected. You can provide an Observable, Promise, Array, or Iterable. at Object.push../node_modules/rxjs/internal/util/subscribeTo.js.exports.subscribeTo (subscribeTo.js:42) at Object.subscribeToResult (subscribeToResult.js:7) at SwitchMapSubscriber.push../node_modules/rxjs/internal/operators/switchMap.js.SwitchMapSubscriber._innerSub (switchMap.js:58) at SwitchMapSubscriber.push../node_modules/rxjs/internal/operators/switchMap.js.SwitchMapSubscriber._next (switchMap.js:51) at SwitchMapSubscriber.push../node_modules/rxjs/internal/Subscriber.js.Subscriber.next (Subscriber.js:64) at MapSubscriber.push../node_modules/rxjs/internal/operators/map.js.MapSubscriber._next (map.js:52) at MapSubscriber.push../node_modules/rxjs/internal/Subscriber.js.Subscriber.next (Subscriber.js:64) at MapSubscriber.push../node_modules/rxjs/_esm5/internal/operators/map.js.MapSubscriber._next (map.js:41) at MapSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber.next (Subscriber.js:54) at FilterSubscriber.push../node_modules/rxjs/_esm5/internal/operators/filter.js.FilterSubscriber._next (filter.js:38)

jgan42 avatar Jun 23 '18 00:06 jgan42

@jgan42 Can you create a stackblitz to recreate the problem so I can debug?

davideast avatar Jun 24 '18 14:06 davideast

Just ran into this issue also with another dev, where are you importing switchmap and of from? check that it's rxjs and rxjs/operators

hungerregnuh avatar Jun 28 '18 17:06 hungerregnuh

Hi,

The auto import gave me this : import {switchMap} from 'rxjs/internal/operators';

effectively it works well with : import {switchMap} from 'rxjs/operators'; Tested with firebase 5.0.4 to 5.2.0.

My bad, thanks for your time.

jgan42 avatar Jun 30 '18 11:06 jgan42

Oi,

A importação automática me deu isto: import {switchMap} from 'rxjs/internal/operators';

efetivamente funciona bem com: import {switchMap} from 'rxjs/operators'; Testado com firebase 5.0.4 a 5.2.0.

Meu mal, obrigado pelo seu tempo.

Perfect!!!!

Tks!!! :)

thiagoarantesprado avatar Jun 15 '19 12:06 thiagoarantesprado