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

Resource fixes #6211

Merged
merged 11 commits into from Feb 14, 2018
Merged

Resource fixes #6211

merged 11 commits into from Feb 14, 2018

Conversation

tfili
Copy link
Contributor

@tfili tfili commented Feb 13, 2018

  • We now handle multiple parameters with the same name.
    • addQueryParameters has been replaced with setQueryParameters and appendQueryParameters.
    • addTemplateValues has been replaced with setTemplateValues for consistency.
  • We added static and prototype methods for the other methods
    • PUT, PATCH, DELETE
    • OPTIONS and HEAD have methods that return a dictionary object of the headers
  • loadWithXhr has been fixed to actually pass through the method. Even though it is deprecated, this was broken in the last release and can lead to weird bugs if a user was doing anything but a GET.
  • Resource.clone now functions as expected. Internal logic was moved into the private method Resource.createIfNeeded.
  • server.js was modified to handle OPTIONS requests, so it can be tested.
  • Various doc fixes

@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.

🌍 🌎 🌏

var value = result[param];
var q2Value = q2[param];
if (defined(value)) {
if (!Array.isArray(value)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it make things simpler to have the query properties always be arrays?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Possibly, however we would need to change functionality of objectToQuery and queryToObject to do this. Then a user could still queryParameters property and change it manually, so we'd have to implement a mechanism to prevent that. Since its already done I think it'll be more trouble than its worth.

*
*
* @example
* // Load a single resource asynchronously. In real code, you should use loadBlob instead.
Copy link
Contributor

Choose a reason for hiding this comment

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

What does In real code, you should use loadBlob instead mean? Is that just a bad copy/paste? It's in the doc for the next few functions too

Copy link
Contributor

Choose a reason for hiding this comment

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

I think the answer is "both" 😄

Ge means that you wouldn't normally use fetch to retrieve a blob, you would call the more specific fetchBlob instead.

@tfili I would recommend deleting this comment and updating the comment paragraph above to say that we recommend using the more specific functions in the class, i.e. fetchJson, fetchImage, etc.. rather than calling fetch directly, but we expose this for the cases where the user does not want the data to be interested in anyway way. Then just rename blob in the below example to body and we're good to go.

@hpinkos
Copy link
Contributor

hpinkos commented Feb 14, 2018

This all looks good to me @tfili

@mramato do you want to take a quick look too?

server.js Outdated
@@ -55,7 +55,14 @@
app.use(function(req, res, next) {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept');
next();
//intercepts OPTIONS method
if ('OPTIONS' === req.method) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this still needed if we're just going to mock OPTIONS in the test? (If not I would remove it since people unfortunately use our code as a basis for their own server).

/**
* @private
*/
function combineQueryParameters(q1, q2, preserveQueryParameters) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add some comments about what this function is actually doing (i.e. perhaps just some examples of expected input/output behavior). The intent of these types of functions are a pain to figure out once you haven't looked at it in a while (or are seeing it for the first time).

@@ -239,7 +278,10 @@ define([
*/
Resource.createIfNeeded = function(resource, options) {
if (resource instanceof Resource) {
return resource.clone();
// Keep existing request
Copy link
Contributor

Choose a reason for hiding this comment

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

Please expand this comment to explain why we are keeping it.

*
*
* @example
* // Load a single resource asynchronously. In real code, you should use loadBlob instead.
Copy link
Contributor

Choose a reason for hiding this comment

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

This one is definitely a copy and paste error, remove the commend and change blob to body (I assume DELETE returns the body without interpreting it at all?)

Copy link
Contributor

Choose a reason for hiding this comment

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

Nevermind, I read the doc, the example should definitely specify a response type (probably JSON) so that users see a real world use case.

@mramato
Copy link
Contributor

mramato commented Feb 14, 2018

I think that's all I have. Thanks @tfili

@tfili
Copy link
Contributor Author

tfili commented Feb 14, 2018

@mramato @hpinkos I think that should do it.

@mramato
Copy link
Contributor

mramato commented Feb 14, 2018

I resolved the CHANGES conflict.

@hpinkos this is good to me, please merge when you're happy.

@hpinkos
Copy link
Contributor

hpinkos commented Feb 14, 2018

Thanks @tfili!

@hpinkos hpinkos merged commit 4e13768 into master Feb 14, 2018
@hpinkos hpinkos deleted the resource-fixes branch February 14, 2018 21:57
@mramato
Copy link
Contributor

mramato commented Feb 15, 2018

Looks like we missed one, fetchJsonp is still calling addQueryParameters which is deprecated. @tfili can you open a PR with the fix. Thanks.

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

4 participants