Since I'm working on angular / firebase, I'm a bit confused of the good use of Rxjs with firebase on Angular 2+ more particularly with Observable/Subject with firebase.on/once. I didn't found good examples of that.
First of all I think my understand of each one is ok (where I'm confused is when combining them), not sure about my explanations :
- Subject: a data producer and a data consumer, observables who subscribe to this subject will be like "dependent"
- Observable: a data producer where datas will be more "independent"
- firebase.database().ref(...).on...: query called every time data change
- firebase.database().ref(...).once...: query called once
Some questions/examples of what I saw (that confused me):
- Using "firebase.database().ref(..).once..." (or .on) with Observable: What's the point of using Observable here if query already give us what we need ?
- When is it better to use Subject over Observable + setters to update "myself" datas ?
- Imagine you have /books and each book have some attributs (id, author, pages, title...) (in your code it will be stored in Book[]) and you want to update for example author, is it better to update just this attribute or all books with firebase (firebase.database().ref('/books').set(this.books);) ? I don't know why but I feel more secure just updating attribute than all objects but I often see the update with all objects, what's the best method ?
- (Edit) What's the point of using firebase.database().on... with Subjects ? once will give the same result and will be more optimal (less queries) no ?