Nativescript-plugin-firebase: Can't read number field where value is greater than 0

Created on 19 Oct 2016  Â·  16Comments  Â·  Source: EddyVerbruggen/nativescript-plugin-firebase

For some reasons, when I do a query request to get my objects, some properties of the json objects are missed. Below the query :

return firebase.query( data => { if(data.value) { Object.keys(data.value).forEach(key => { this.results.push(data.value[key]); // Here I dont get exactly the JSON, some properties disapears..... } } }, "/ads/", { orderBy: { type: firebase.QueryOrderByType.KEY }}) .then(result => { return result; }) );

Properties of type number are not loaded (totalProduct and state) when value is greater than 0. capture d ecran 2016-10-19 a 19 02 40

Regards

bug iOS

All 16 comments

I am experiencing this issue as well. This is really bizarre. I can retrieve strings, not numbers. Should I convert everything to a string? This is crazy. In the example below, everything does load the first time, but then on subsequent loads of the app or when I go to a detail page, anything that is a number is omitted entirely. For example, I need all this data back:

screenshot 2016-12-05 21 57 11

but what I get is only that data that is a string.

iOS/Android/both?

I've tested on iOS 10 and Android 7 devices with the demo app as well as the query of @fsandreau and everything works fine with my data structure:

screen shot 2016-12-06 at 11 10 14

Whenever I change fi. the age property the data is reflected correctly in my app. Any idea how this is different from your usages?

Can you guys add console.log("Query result: " + JSON.stringify(result)); as the first line in the onValueEvent callback function?

@jlooper If that doesn't shed any new light on this issue then please paste your query code here as well as a minimal export of your db:

screen shot 2016-12-06 at 11 13 59

hi, the very consistently bizarre behavior is that, on initial creation of the app I get the expected data:

[{"id":"-KWdk_ax11wUci2ffQra","PracticesCompleted":5,"Reward":"A special prize!","UID":"ade4AX13CLOlBgW1u1hckPZ7Da02","Date":-1479243094507,"Instrument":4,"AdminPassword":"","TeacherEmail":"[email protected]","Name":"Ellen","PracticeLength":5,"PracticesRequired":6}]

and then, if I livesync or just close and reopen the app on device, I get only the strings:

[{"id":"-KWdk_ax11wUci2ffQra","Reward":"A special prize!","UID":"ade4AX13CLOlBgW1u1hckPZ7Da02","AdminPassword":"","TeacherEmail":"[email protected]","Name":"Ellen"}]

@jlooper can I clone some repo to debug this? Also, which platform(s)?

Sorry, it's iOS. I have my repo here: https://github.com/jlooper/practicebuddy-web-mobile

Cool, can you point me at the problematic code as well?

And does Android behave correctly?

thanks for your help. The query to get student data is here: https://github.com/jlooper/practicebuddy-web-mobile/blob/master/src/client/app/frameworks/practicebuddy/services/firebase.service.ts#L152-L195

Genymotion is throwing errors all over so I'm battling Android right now. For the moment, though, maybe the above code makes some sense?

Ah, so you're not using query (@fsandreau does), but addValueEventListener. I'll try to look at it later today.

I've created a sample using both query and adding an event listener. Consistently, when I run the app using tns run ios I get my data back, but when I use tns livesync ios --watch nothing is returned. I would just say, ok, don't use livesync, but I am not convinced that this same problem doesn't occur when I build to device (tns deploy ios --device device-id), close the app, and then reopen it. Here's my repo: https://github.com/jlooper/test-tapper

@fsandreau Does your issue also only pop up with livesync (on iOS)?

@jlooper Seeing similar things. Before I jump to conclusions: can you be very clear (cold hard facts) to me about livesync vs a 'normal' run? Does the problem only pop up when using livesync?

@jlooper changing persist to false in main.ts of your test app seems to fix it. So there may be an incompatibility between Firebase persist-mode and livesync.

holy cow. That seems to have done it! Wow, what a strange behavior!! But thank you @eddy and @fsandreau I hope this might help you!!

Hi all,
Thanks for your work Eddy.
I'm not able to reproduce the same bug without persist mode activated. Its
really wird.
And last think, sorry dor my english, I'm french, but I try to do my best :D

Regards,
Franck

2016-12-06 23:41 GMT+01:00 Jen Looper notifications@github.com:

holy cow. That seems to have done it! Wow, what a strange behavior!! But
thank you @eddy https://github.com/eddy and @fsandreau
https://github.com/fsandreau I hope this might help you!!

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/EddyVerbruggen/nativescript-plugin-firebase/issues/186#issuecomment-265296638,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAwdaO6yMT-3Y4DS3N0iAt2mNZM0EQxvks5rFeSYgaJpZM4KbJhW
.

Hi, I'm having the same problem when running my app on iOS (iPad 9,7 2017), both in livesync and deploy mode, with persist set to true.

Has anyone managed to make their apps run without errors on iOS while keeping persist to true?
Really need to make apps work offline too.

EDIT:

Ok, debugged a bit the code for the plugin, and it seems like I managed to make the app run correctly, by changing firebase.toJsObject in firebase.ios.js, adding the case for NSDecimalNumber.
It seems like when in persist mode, every number different from zero is treated as NSDecimalNumber and not Number.

Here is the code for function. If it works for everyone, maybe @EddyVerbruggen could update the plugin.


firebase.toJsObject = function(objCObj) {
  if (objCObj === null || typeof objCObj != "object") {
    return objCObj;
  }
  var node, key, i, l,
      oKeyArr = objCObj.allKeys;

  if (oKeyArr === undefined) {
    // array
    node = [];
    for (i = 0, l = objCObj.count; i < l; i++) {
      key = objCObj.objectAtIndex(i);
      node.push(firebase.toJsObject(key));
    }
  } else {
    // object
    node = {};
    for (i = 0, l = oKeyArr.count; i < l; i++) {
      key = oKeyArr.objectAtIndex(i);
      var val = objCObj.valueForKey(key);
      switch (types.getClass(val)) {
        case 'NSArray':
        case 'NSMutableArray':
          node[key] = firebase.toJsObject(val);
          break;
        case 'NSDictionary':
        case 'NSMutableDictionary':
          node[key] = firebase.toJsObject(val);
          break;
        case 'String':
          node[key] = String(val);
          break;
        case 'Boolean':
          node[key] = val;
          break;
        case 'Number':
        case 'NSDecimalNumber':
          node[key] = Number(String(val));
          break; 
      }
    }
  }
  return node;
};

Fixed in 4.0.0 thanks to issue #365 (and in retrospect the code posted by @andreacappadona17 which I just saw now).

@jlooper This may render the persist workaround obsolete!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

NickIliev picture NickIliev  Â·  3Comments

bunower picture bunower  Â·  3Comments

EddyVerbruggen picture EddyVerbruggen  Â·  3Comments

thunder413 picture thunder413  Â·  3Comments

ButterMeWaffle picture ButterMeWaffle  Â·  4Comments