dappsnation / akita-ng-fire

Akita ❤️ Angular 🔥 Firebase
MIT License
131 stars 27 forks source link

Valuechanges with ids array return undefined if document doesn't exist #138

Closed RemcoSimonides closed 4 years ago

RemcoSimonides commented 4 years ago

When using valueChanges with a list of ids if one of the ids doesn't exist, it return undefined in the array. Solution

if (idOrQuery.length) {
  docs$ = combineLatest(idOrQuery.map(id => this.db.doc<EntityType>(`${path}/${id}`).valueChanges())).pipe(map(list => 
  list.filter(item => !!item)));
} else {
  docs$ = of([]);
}

https://github.com/dappsnation/akita-ng-fire/blob/3c9ac16fe974348239e33c452ea3f5780811979d/projects/akita-ng-fire/src/lib/collection/collection.service.ts#L477

fritzschoff commented 4 years ago

Hey, I had this discussion with Pierre and he would expect it to be undefined, behavior-wise. Why do you think it is necessary for filtering undefined values in this lib?

RemcoSimonides commented 4 years ago

@GrandSchtroumpf

GrandSchtroumpf commented 4 years ago

This is the only case of valueChanges where you get undefined in the array. Also I'm sure most of developers, especially junior, would expect that. So it might takes time for a developer to understand why there are undefined values in the array. Best case scenario they take time to understand that. Worst case scenario they implement a nasty workaround.

fritzschoff commented 4 years ago

closing this issue, since @RemcoSimonides agrees on the best case scenario.