Closed Bug 1062806 Opened 11 years ago Closed 11 years ago

Use the new shared helper for loading JSON files in the cost control app

Categories

(Firefox OS Graveyard :: Gaia::Cost Control, defect)

ARM
Gonk (Firefox OS)
defect
Not set
normal

Tracking

(b2g-v2.2 fixed)

RESOLVED FIXED
2.1 S5 (26sep)
Tracking Status
b2g-v2.2 --- fixed

People

(Reporter: gsvelto, Assigned: mathieu, Mentored)

References

Details

(Whiteboard: [lang=js])

Attachments

(1 file)

+++ This bug was initially created as a clone of Bug #990047 +++ We can replace the custom code used to load JSON file here with the new shared helper: https://github.com/mozilla-b2g/gaia/blob/cc9fa7ed829b6af23606b41a9e5797866b0a3316/apps/costcontrol/js/config/config_manager.js#L117
Hey, I would like to work on this bug!! Can you please assign it to me? And do i have to replace the above said function with the LazyLoader?
(In reply to gauravmittal from comment #1) > Hey, I would like to work on this bug!! Can you please assign it to me? > And do i have to replace the above said function with the LazyLoader? You've already been assigned bug 1062783 so it's better if you finish that one first before being assigned to another bug.
Hi, Working on some more blocks for the LazyLoader ticket. I used the good and fail premise instead of checking the xhr status as if fetch fail it'll raise the error premise :). UI Tests passed. Lint passed. I indented with 2 spaces like the other files. Thanks for reviewing !
Attachment #8491072 - Flags: review?(gsvelto)
Assignee: nobody → mathieu
Attachment #8491072 - Flags: review?(salva)
Attachment #8491072 - Flags: review?(gsvelto)
Attachment #8491072 - Flags: feedback?(gsvelto)
Status: NEW → ASSIGNED
Comment on attachment 8491072 [details] [review] Github PR for Bug 1062806 Using LazyLoader and Premises Pretty straightforward, LGTM.
Attachment #8491072 - Flags: feedback?(gsvelto) → feedback+
Grabriel, in current `LazyLoad.getJSON()` I found that passing an invalid or non-existent URL will resolve the promise with `null`. You've this commented in the function so I assume it's an intended behavior but this supposes, in many cases, to check for `result !== null` and probably to repeat the rejection code for this case. What do you think?
Flags: needinfo?(gsvelto)
Comment on attachment 8491072 [details] [review] Github PR for Bug 1062806 Using LazyLoader and Premises Please Gabriel, ask for my review again when you answer me. Thank you.
Attachment #8491072 - Flags: review?(salva)
(In reply to Salvador de la Puente González [:salva] from comment #5) > Grabriel, in current `LazyLoad.getJSON()` I found that passing an invalid or > non-existent URL will resolve the promise with `null`. You've this commented > in the function so I assume it's an intended behavior but this supposes, in > many cases, to check for `result !== null` and probably to repeat the > rejection code for this case. > > What do you think? When the function was written I had a good look around the code in gaia and most of it didn't care about the response. It seems that in most places we'd rather check the XMLHttpRequest 'response' field against null rather than look at the return code and acting on that hence the decision to write the method that way. That being said I think it would be cleaner from a high-level perspective to reject() in the cases you mention (e.g. malformed JSON code, 4xx status codes, etc...) so I'm OK to open a bug about that purpose. However there's one thing that should be taken care of if we follow that road: ensuring that existing uses are compatible with it and removing existing useless null checks (plus changing the in-code documentation to explicitly say that resolve() will always return a valid object and all other cases will be reject()ed with an appropriate error code).
Flags: needinfo?(gsvelto)
Attachment #8491072 - Flags: review?(salva)
(In reply to Gabriele Svelto [:gsvelto] from comment #7) > (In reply to Salvador de la Puente González [:salva] from comment #5) > > Grabriel, in current `LazyLoad.getJSON()` I found that passing an invalid or > > non-existent URL will resolve the promise with `null`. You've this commented > > in the function so I assume it's an intended behavior but this supposes, in > > many cases, to check for `result !== null` and probably to repeat the > > rejection code for this case. > > > > What do you think? > > When the function was written I had a good look around the code in gaia and > most of it didn't care about the response. It seems that in most places we'd > rather check the XMLHttpRequest 'response' field against null rather than > look at the return code and acting on that hence the decision to write the > method that way. > > That being said I think it would be cleaner from a high-level perspective to > reject() in the cases you mention (e.g. malformed JSON code, 4xx status > codes, etc...) so I'm OK to open a bug about that purpose. However there's > one thing that should be taken care of if we follow that road: ensuring that > existing uses are compatible with it and removing existing useless null > checks (plus changing the in-code documentation to explicitly say that > resolve() will always return a valid object and all other cases will be > reject()ed with an appropriate error code). Yep. Indeed, a simply `null` value inside a JSON object it's perfectly valid [1] so acting this way we can totally distinguish between a successful retrieve and failure cases. [1] http://www.json.org/
Comment on attachment 8491072 [details] [review] Github PR for Bug 1062806 Using LazyLoader and Premises It's ok for me but before merging address the problem on GitHub. I repeat here: 1.- Let's file a bug for changing `getJSON()` implementation. 2.- Let's add the null check now. 3.- Leave a TODO comment about remove when the bug is fixed.
Attachment #8491072 - Flags: review?(salva) → review+
(In reply to Gabriele Svelto [:gsvelto] from comment #7) > That being said I think it would be cleaner from a high-level perspective to > reject() in the cases you mention (e.g. malformed JSON code, 4xx status > codes, etc...) so I'm OK to open a bug about that purpose. However there's > one thing that should be taken care of if we follow that road: ensuring that > existing uses are compatible with it and removing existing useless null > checks (plus changing the in-code documentation to explicitly say that > resolve() will always return a valid object and all other cases will be > reject()ed with an appropriate error code). Maybe we can add an optional `default` parameter preventing the function to reject and simply resolving with that value.
Depends on: 1069808
Filed bug 1069808, see if the description there is sensible. The idea of a `default` parameter is also intriguing but I'd rather wait to see if there's actual code which might need it. Let's keep things simple for now.
Thank a lot Gabriel!
Comment on attachment 8491072 [details] [review] Github PR for Bug 1062806 Using LazyLoader and Premises I have updated the PR with the workaround and put the TODO. Would you mind to take a look at the PR ? If it's ok, I'll mark it as checkin-needed. I should be able to take care of the bug related to lazy_loader today or tomorrow. Thanks.
Attachment #8491072 - Flags: feedback?(salva)
Comment on attachment 8491072 [details] [review] Github PR for Bug 1062806 Using LazyLoader and Premises I'm removing the review flag. Please, consider the comment on GitHub and ask again. Thank you.
Attachment #8491072 - Flags: review+
Attachment #8491072 - Flags: feedback?(salva)
Attachment #8491072 - Flags: feedback-
Comment on attachment 8491072 [details] [review] Github PR for Bug 1062806 Using LazyLoader and Premises Hi salvador, I just updated the PR with your comments and removed the else clause. We had to have the on error func as if lazy_loader returns a reject premise, we can catch it with this func and then do what we used to do in the old xhr error. Thanks for reviewing.
Attachment #8491072 - Flags: review?(salva)
Comment on attachment 8491072 [details] [review] Github PR for Bug 1062806 Using LazyLoader and Premises Address the little nit on GitHub and it's done. Thank you very much.
Attachment #8491072 - Flags: review?(salva) → review+
Attachment #8491072 - Flags: feedback- → feedback+
(In reply to Salvador de la Puente González [:salva] from comment #16) > Comment on attachment 8491072 [details] [review] > Github PR for Bug 1062806 Using LazyLoader and Premises > > Address the little nit on GitHub and it's done. Thank you very much. Done. Thanks a lot for guiding me through it.
Keywords: checkin-needed
Closing, as it was already merged in master
Status: ASSIGNED → RESOLVED
Closed: 11 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: