Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds request queueing to API resource fetch, adds save method to Models. #279

Closed
wants to merge 6 commits into from

Conversation

rtibbles
Copy link
Member

Summary

This adds the request queueing that @jamalex had previously suggested, to handle the situation where multiple code points call fetch on the same object.

In addition, with this in hand, I implemented a save method for the Model class, which accepts an object with the properties to save, it also obeys the request queue, so any existing fetches or saves will be resolved before it is initiated.

TODO

  • Have tests been written for the new code?
  • Has documentation been written/updated?

}, (response) => {
logging.error('An error occurred', response);
reject(response);
const promise = new Promise((resolve, reject) => {

This comment was marked as spam.

@codecov-io
Copy link

codecov-io commented Jul 16, 2016

Current coverage is 82.14% (diff: 13.40%)

Merging #279 into master will decrease coverage by 0.90%

@@             master       #279   diff @@
==========================================
  Files            92         96     +4   
  Lines          2950       3209   +259   
  Methods         151        181    +30   
  Messages          0          0          
  Branches        345        367    +22   
==========================================
+ Hits           2450       2636   +186   
- Misses          477        550    +73   
  Partials         23         23          

Powered by Codecov. Last update 82a9320...de26bab

// Clean up the reference to this promise
this.promises.splice(this.promises.indexOf(promise), 1);
}, (response) => {
logging.error('An error occurred', response);

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

@indirectlylit indirectlylit changed the title Adds request queueing to API resource fetch, adds save method to Models. POST-MMVP - Adds request queueing to API resource fetch, adds save method to Models. Jul 18, 2016
// Clean up the reference to this promise
this.promises.splice(this.promises.indexOf(promise), 1);
});
}
});

This comment was marked as spam.

This comment was marked as spam.

@jamalex
Copy link
Member

jamalex commented Jul 19, 2016

Since this is targeted post-MMVP, I don't feel so bad asking: any chance we can look at how we might write client-side tests for code like this? We have really good coverage on the server-side stuff, and very minimal client-side coverage. Lots of complicated/possibly fragile logic in here, and would be good to have it covered.

@rtibbles
Copy link
Member Author

I left the checkbox for tests in place for precisely that reason, yes.

There is currently 0 code coverage for the entire api_resource.js - I plan to rectify that.

@jamalex
Copy link
Member

jamalex commented Jul 19, 2016

Nice -- will be good to have some solid examples of client-side mocking/testing to inspire others. Perhaps putting some notes into the docs about how to approach this, as a reference, in the process.

@rtibbles
Copy link
Member Author

@rtibbles
Copy link
Member Author

Although, I admit the docs could be expanded upon a little: https://github.com/learningequality/kolibri/blob/master/docs/dev/frontend.rst#unit-testing

@jamalex
Copy link
Member

jamalex commented Jul 19, 2016

Cool, hadn't seen the tests or docs -- looks great. Yeah, some unpacking/elaboration of the docs instructions may be good over time. And, when you're back in August, perhaps a hack session tech talk.

@indirectlylit indirectlylit changed the title POST-MMVP - Adds request queueing to API resource fetch, adds save method to Models. Adds request queueing to API resource fetch, adds save method to Models. Jul 19, 2016
@indirectlylit indirectlylit added the TODO: needs review Waiting for review label Jul 25, 2016
@@ -28,35 +28,106 @@ class Model {

// force IDs to always be strings - this should be changed on the server-side too
this.attributes[this.resource.idKey] = String(this.attributes[this.resource.idKey]);

This comment was marked as spam.

@66eli77
Copy link
Contributor

66eli77 commented Jul 29, 2016

@rtibbles #313 inherits the changes from this PR, please target #313 . I'm going to close this PR.

@66eli77 66eli77 closed this Jul 29, 2016
@rtibbles rtibbles deleted the persistence branch April 15, 2017 00:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
TODO: needs review Waiting for review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants