0

I have a view that subscribe to a FirebaseListObservable and a form that does CRUD operations on a range of objects in that list.

It will iterate over the keys and update the database like so:

let list = this.angularFire.database.list('items/' + listkey);
keys.forEach((key) => list.update(key, item[key]));

The problem is that the subscription issue a new list for each update, whereas I only need the list when all the transactions are complete.

I have tried to manipulate the list before updating the database using the FirebaseObjectObservable on the listkey but it throws an error due to invalid characters in the metafields (like $key and $exist).

Right now I am using a debounceTime on the subscription but I am not sure if that is the proper implementation or not.

Is there a way to concat the updates into a single transaction?

unitario
  • 6,295
  • 4
  • 30
  • 43
  • 1
    There're `merge` and `concat` operators but from your description I don't really understand what is the problem and how is it implemented... – martin Apr 03 '17 at 07:26
  • I could elaborate on the implementation some more, but I think it is pretty generic. I want to update parts of a `FirebaseListObservable` as a single transaction. Not sure how I would do that using `merge` or `concat` operators but thanks for the suggestion. – unitario Apr 03 '17 at 07:40
  • 2
    This is answered here: http://stackoverflow.com/questions/17437695/firebase-how-do-i-update-multiple-resources-atomically – Velko Ivanov Apr 03 '17 at 07:54
  • Yes, that seems to be it. Thanks, will try and implement! – unitario Apr 03 '17 at 08:10
  • 1
    Yep, follow the [answer linked above](http://stackoverflow.com/a/17438028/6680611) and call `list.$ref.ref.update` where `list` is the observable in your question. Note that for multi-location updates you don't call `list.update` (which is a wrapper around the SDK); you call it directly on the SDK ref. – cartant Apr 03 '17 at 08:42

0 Answers0