-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Conversation
@tfili, thanks for the pull request! Maintainers, we have a signed CLA from @tfili, so you can review this at any time.
I am a bot who helps you make Cesium awesome! Contributions to my configuration are welcome. 🌍 🌎 🌏 |
My vote is to deprecate and ultimately remove all of the |
So I've deprecated all the functions and replaced their usage within Cesium/Sandcastle. |
Sorry for not looking at this yet, will try to get to it on Thursday, but might be until Friday. |
Bump. |
Another bump. |
@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. |
We deprecated a bunch of parameters to the |
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. |
Apps/Sandcastle/CesiumSandcastle.js
Outdated
@@ -957,11 +958,13 @@ require({ | |||
} | |||
} | |||
}; | |||
return loadWithXhr({ | |||
|
|||
var resource = new Resource({ | |||
url : 'https://api.github.com/gists', | |||
data : JSON.stringify(data), | |||
method : 'POST' |
There was a problem hiding this comment.
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(), |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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?
Source/Core/Resource.js
Outdated
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
resource -> request?
Source/Core/Resource.js
Outdated
* @memberof Resource.prototype | ||
* @type {Object} | ||
*/ | ||
lastResponse: { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
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 |
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. |
@mramato Do we want to move all the |
Source/Core/Resource.js
Outdated
* @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) { |
There was a problem hiding this comment.
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.
@mramato I think this should be good now. Also added tests for the static calls because they aren't tested with the |
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. |
Actually, one last thing. Update CHANGES and make sure to edit the previous entry regarding proxy et al. |
@mramato I've update CHANGES |
Nice work @tfili |
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:
Resource
, so we can get content-length and stuff like that.