Nativescript-plugin-firebase: Atomic multi-location update

Created on 15 Mar 2017  路  8Comments  路  Source: EddyVerbruggen/nativescript-plugin-firebase

Hi! Would it be difficult to add atomic multi-location updates as shown in this Firebase Blog post:

var ref = new Firebase("https://<YOUR-FIREBASE-APP>.firebaseio.com");
// Generate a new push ID for the new post
var newPostRef = ref.child("posts").push();
var newPostKey = newPostRef.key();
// Create the data we want to update
var updatedUserData = {};
updatedUserData["user/posts/" + newPostKey] = true;
updatedUserData["posts/" + newPostKey] = {
  title: "New Post",
  content: "Here is my new post!"
};
// Do a deep-path update
ref.update(updatedUserData, function(error) {
  if (error) {
    console.log("Error updating data:", error);
  }
});

I can try my hand on a pull request (tbh wary, first-ever PR if so) but:
1) should this plugin's firebase.update() be edited, or a separate method be instead stubbed out for multi-location updates (different parameter types in firebase.d.ts); and
2) I'm not sure how to work/test out the iOS counterpart; I'm not that familiar with Obj-C

Most helpful comment

I just tried the atomic multi-location update. The behavior that I seem to be getting is a complete overwrite of the all the keys in the path specified. Is this the intended behavior? Since we are using update I thought only the value of the specified keys would be updated and the rest of the keys would remain unchanged.
@lorcanfurey , @davorpeic could you let me know if this is the behavior you observe?

Thanks

All 8 comments

Hi @lorcanfurey this is already working, just missing from the docs, check question and example from this issue #229

davor

Thanks for the heads up @davorpeic!

I just tried the atomic multi-location update. The behavior that I seem to be getting is a complete overwrite of the all the keys in the path specified. Is this the intended behavior? Since we are using update I thought only the value of the specified keys would be updated and the rest of the keys would remain unchanged.
@lorcanfurey , @davorpeic could you let me know if this is the behavior you observe?

Thanks

Just verified, I am also experiencing @anuragd7 's issue; all other fields at the intended path get nuked

Any ideas @davorpeic ?

Hey @anuragd7 and @lorcanfurey
I'm just checkin what firebase ios sdk docs say, and I see that the update method is identical to what Eddy is using, but it doesn't say anything on how the update/overwrite is done.

One possible workaround would be defining each field you want to update as separate update, and update it as a part of atomic update, that way you would actually update each individual field needed to be updated?

This is not tested, but I suppose it should work, can you try?

var companiesPath = 'companies/company_name';
var usersPath = 'users/user_nickname';

var data = {};
data[companiesPath] = 'Best Company Name';
data[usersPath] = 'John';

firebase.update('/', data);

dp

Hi @davorpeic, That's what I ended up doing and can confirm it works.馃憤

Thanks for this guys. If anyone is up for an update of the plugin docs I'd be happy to merge a PR.

Scrap that - that's exactly what @davorpeic has already done ;)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

thunder413 picture thunder413  路  3Comments

vchimev picture vchimev  路  3Comments

Aceman18 picture Aceman18  路  3Comments

phatakrajan picture phatakrajan  路  4Comments

NickIliev picture NickIliev  路  3Comments