angular / angularfire

Angular + Firebase = ❤️
https://firebaseopensource.com/projects/angular/angularfire2
MIT License
7.68k stars 2.19k forks source link

Bug: doc(...).snapshotChanges does not return DocumentChangeAction #1762

Closed Bielik20 closed 3 years ago

Bielik20 commented 6 years ago

Version info

Angular: 6.0.3

Firebase: 5.1.0

AngularFire: 5.0.0-rc.11

Other: Windows 10, browser (chrome)

How to reproduce these conditions

Subscribe to any DOCUMENT with "snapshotChanges". Eg:

this.afs.collection('myCollection').doc('myDocId')
  .snapshotChanges()
  .pipe(tap(res => console.log(res))
  .subscribe()

Debug output

image

Expected behavior

According to documentation snapshotChanges should return Observable<DocumentChangeAction<T>>.

Actual behavior

What it does return is Observable<Action<DocumentSnapshot<T>>>. type field is always "value" even if I delete record and payload does not seem to contain actual data (I was not able to find it).

Remarks

snapshotChanges works well on collections returning Observable<DocumentChangeAction<T>[]>. Problem occurs only when using it on document.

Noext commented 6 years ago

same issue on ubuntu

this.db.collection('polls').doc('id').snapshotChanges().subscribe(poll => {})

poll.payload is not a DocumentChange, so you can't call .doc property to retrieve le document

davideast commented 6 years ago

@Bielik20 @Noext We are changing doc.snapshotChanges() to return a Observable<DocumentSnapshot<T>> in the next release. The type is useless on it because it is always a value update regardless of the type of change.

CheckMater commented 6 years ago

How can I know which change occurred (added, modified, removed) if the type field is always equal to "value"?

Thanks.

AnthonyGilliam commented 6 years ago

Hi @davideast thanks for all the hard work on this great project, love the way it auto-syncs data. Favor: could one of the contributors update the docs on the doc.snapshotChanges() method? I'm using @angular/fire 5.0.0 and this change is in there, but I have next to no idea how to use this method now.

THANKS!

rubenCortes commented 5 years ago

The problem persists to the present date. I just met it.

Malspherus commented 5 years ago

@davideast what release were you referencing? I couldn't find anything finished or a pull request and the unusable type causes quite dirty code down the line.

mcarriere commented 4 years ago

Still having this issue to this day

KingDarBoja commented 4 years ago

Having same issue as author, the type on Action type is always returning value no matter what. Maybe we must use snapshotChanges() on a collection-document chain instead?

sur97c commented 4 years ago

I have same issue, is imposible to know what type of changes was performed over one specific document using the snapshotChanges, someone know some workaround to resolve this issue?

jamesdaniels commented 3 years ago

closing in favor of #2108