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

Moved all low level load functions into Resource #6138

Merged
merged 22 commits into from
Jan 31, 2018

Conversation

tfili
Copy link
Contributor

@tfili tfili commented Jan 20, 2018

Right now all the Resource functions are all private and the load functions just call them.

It also prevents contention issues, since a Resource can only be requested once.

We need to figure out if we're gonna deprecate the load functions or just roll with what we have. We can copy the tests over if we decide to get rid of the load functions.

TODO:

  • Possibly add some response headers to the Resource, so we can get content-length and stuff like that.
  • Figure out whats going on with deprecation and tests.

Sorry, something went wrong.

@cesium-concierge
Copy link

Signed CLA is on file.

@tfili, thanks for the pull request! Maintainers, we have a signed CLA from @tfili, so you can review this at any time.

⚠️ I noticed that CHANGES.md has not been updated. If this change updates the public API in any way, fixes a bug, or makes any non-trivial update, please add a bullet point to CHANGES.md and comment on this pull request so we know it was updated. For more info, see the Pull Request Guidelines.


I am a bot who helps you make Cesium awesome! Contributions to my configuration are welcome.

🌍 🌎 🌏

@mramato
Copy link
Contributor

mramato commented Jan 22, 2018

My vote is to deprecate and ultimately remove all of the loadXXX functions. I can't think of a good reason to keep them around, @shunter?

@tfili
Copy link
Contributor Author

tfili commented Jan 22, 2018

So I've deprecated all the functions and replaced their usage within Cesium/Sandcastle.

Tom Fili added 2 commits January 23, 2018 14:41

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
@tfili
Copy link
Contributor Author

tfili commented Jan 23, 2018

Resolved conflicts. Bump.

CC @mramato @hpinkos @shunter

@mramato
Copy link
Contributor

mramato commented Jan 25, 2018

Sorry for not looking at this yet, will try to get to it on Thursday, but might be until Friday.

@tfili
Copy link
Contributor Author

tfili commented Jan 26, 2018

Bump.

@tfili
Copy link
Contributor Author

tfili commented Jan 29, 2018

Another bump.

@mramato
Copy link
Contributor

mramato commented Jan 29, 2018

@tfili do you care if we merge this Feb 2nd? Or is there a really good reason to get it into this release? I'll try and review later today either way.

@tfili
Copy link
Contributor Author

tfili commented Jan 29, 2018

We deprecated a bunch of parameters to the load* functions. This removed those and actually deprecated the whole functions. If people were using them, they may find it odd that we did that in back to back releases, but that's probably about it.

@mramato
Copy link
Contributor

mramato commented Jan 29, 2018

Avoiding churn is certainly a good reason. Since no one else seems interested in reviewing this, I'll do a thorough review tonight and merge in the morning if nothing major.

@@ -957,11 +958,13 @@ require({
}
}
};
return loadWithXhr({

var resource = new Resource({
url : 'https://api.github.com/gists',
data : JSON.stringify(data),
method : 'POST'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does method still need to be part of the resource? Wouldn't this just be controlled by the function you are calling? For example, it seems weird to call fetch below, why not just have a post function on Resource?

@@ -144,8 +144,8 @@
function offsetByDistance() {
Sandcastle.declare(offsetByDistance);
Cesium.when.all([
Cesium.loadImage('../images/Cesium_Logo_overlay.png'),
Cesium.loadImage('../images/facility.gif')
Cesium.Resource.createIfNeeded('../images/Cesium_Logo_overlay.png').fetchImage(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

createIfNeeded is private, so it shouldn't be used in Sandcastle examples. To keep these as one-liners, the better approach would be to have a static Resource.fetchImage that just takes the same parameters as the Resource constructor and just returns a promise.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment applies anywhere we create a resource just to load and then throw it away. I originally thought this could wait for a future PR, but I think these examples will get overly verbose if we don't do it now.

var requestString = endpoint + query;
return Cesium.loadJson(requestString)
var resource = new Cesium.Resource({
url: endpoint + query
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we use Resource properly and pass in the query parameters separately instead of globbing them together?

if (defined(options.proxy)) {
resource.proxy = options.proxy;
}
if (defined(options.request)) {
resource.request = options.request;
} else {
// Clone the resource so we keep all the throttle settings
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resource -> request?

* @memberof Resource.prototype
* @type {Object}
*/
lastResponse: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did this property exist elsewhere already, or is it new? Are we worried it could lead to bloated memory usage?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea was to set the response that is returned so the caller can get information about the response besides just the data. This would make it possible to avoid hacks like #1353. It's not used so I can remove it.

All imagery and terrain providers discard the resource once its received, so we'd probably be ok as far as bloating goes.

@mramato
Copy link
Contributor

mramato commented Jan 29, 2018

Since we're going "whole hog" here, I feel like Resource should take either a string or object in its constructor, so that along with the static functions I asked for, we can do Resource.fetchImage('someurl');, otherwise I feel like the API is going to be taking a step back in usability.

@mramato
Copy link
Contributor

mramato commented Jan 29, 2018

I did a cursory review and that's all I had. I'll take a closer look once we implement (or discuss) the ideas I brought up.

@tfili
Copy link
Contributor Author

tfili commented Jan 30, 2018

@mramato
I added static methods for all the fetch* methods.
I added a post method on the prototype and a static version.
I let constructor now take a URL or an object.
Cleaned up Sandcastle examples.

Do we want to move all the load* tests into resource as fetch* tests?

* @param {String} url The url of the resource.
* @returns {Promise.<Object>|undefined} a promise that will resolve to the requested data when loaded. Returns undefined if <code>request.throttle</code> is true and the request does not have high enough priority.
*/
Resource.fetchJson = function (url) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be an object or a url, right? We should make sure we document these consistently. My assumption is that the static functions have the same function signature as the constructor, plus any function-specific options, (like post data). We can talk face to face when you get in to avoid PR churn if that helps.

@tfili
Copy link
Contributor Author

tfili commented Jan 30, 2018

@mramato I think this should be good now. Also added tests for the static calls because they aren't tested with the load* tests.

@mramato
Copy link
Contributor

mramato commented Jan 30, 2018

Thanks @tfili, I submitted one minor tweak to Sandcastle (just to use the shorthand versions) and I'll merge as soon as this goes green.

@mramato
Copy link
Contributor

mramato commented Jan 30, 2018

Actually, one last thing. Update CHANGES and make sure to edit the previous entry regarding proxy et al.

@tfili
Copy link
Contributor Author

tfili commented Jan 30, 2018

@mramato I've update CHANGES

@mramato
Copy link
Contributor

mramato commented Jan 31, 2018

Nice work @tfili

@mramato mramato merged commit 87716cd into master Jan 31, 2018
@mramato mramato deleted the load-functions-into-resource branch January 31, 2018 01:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants