2

I am using a library called redux-firebasev3 to make three separate set calls to firebase.

for(let object of array) {
    ....
    firebase.set(`/object/${id}/attr1`, attr1);
    firebase.set(`/object/${id}/attr2`, attr2);
    firebase.set(`/object/${id}/attr3`, attr3);
}

The array has a length of 32. When it gets to about the 8th to the last object chrome dev tools freeze up and crash. Is there a better way I should be making these calls? What could be the reason for the failure? I can't see errors because dev tools crash.

Here is the link to set function in the library.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Josh Birdwell
  • 745
  • 4
  • 21

2 Answers2

1

Not sure if I understand correctly, but are you looking for this?

firebase.set(`/object/${id}`, { attr1: attr1, , attr2: attr2, attr3: attr3 });
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • Yes, I had just wanted suggestions for better ways of making three calls. That it would hopefully speed it up and less prone to crashing. – Josh Birdwell Aug 24 '16 at 15:20
  • Will this override the other attributes on the object. Say it has an attribute 4 and you don't need to set it. Will it only have three attributes after this call? – Josh Birdwell Aug 24 '16 at 15:56
  • The speed up you'll gain from combining calls will be minimal, since [Firebase pipelines these requests](http://stackoverflow.com/questions/35931526/speed-up-fetching-posts-for-my-social-network-app-by-using-query-instead-of-obse/35932786#35932786). But the update will be atomic on the wire, which means that up `attr1` is invalid (according to your security rules), the entire `set()` will fail in my variant. – Frank van Puffelen Aug 24 '16 at 16:00
  • Yes, calling `set()` will overwrite all data at the location. If you want to update the properties, call `update()`. I highly recommend that you check out [Firebase's JavaScript guid](https://firebase.google.com/docs/database/web/save-data) and [reference docs](https://firebase.google.com/docs/reference/js/firebase.database), which covers a lot of these cases. – Frank van Puffelen Aug 24 '16 at 16:02
  • Thanks for the help, Frank! – Josh Birdwell Aug 24 '16 at 16:05
0

Disclaimer: I am one of the author's of redux-firebasev3

Not sure if I understand the original question, but to clarify:

To set multiple attributes in one object all at once:

firebase.set(`/object/${id}`, { attr1: "some val", attr2: "some string", attr3: "some other" });

To set multiple attributes to multiple separate locations:

firebase.set(`/messages/${id}`, { attr1: "some val", attr2: "some string" }) firebase.set(`/objects/${id}`, { attr1: "some val", attr2: "some string" })

To set update an existing path:

firebase.update(`/messages/${id}`, { attr1: "some val", attr2: "some string" })

The goal was to have the library as closley mirror the Firebase API as possible, including things like set and update.

The repo now includes examples like the simple example

Scott
  • 1,575
  • 13
  • 17