Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(439)

Unified Diff: third_party/polymer/v1_0/components/iron-ajax/iron-ajax.html

Issue 1187823002: Update Polymer components and re-run reproduce.sh (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/polymer/v1_0/components/iron-ajax/iron-ajax.html
diff --git a/third_party/polymer/v1_0/components/iron-ajax/iron-ajax.html b/third_party/polymer/v1_0/components/iron-ajax/iron-ajax.html
index 47d202b4151a946307021c0295f9a38eda192972..8137dc8fdbfe22637ed4b5595f54859a05ee52be 100644
--- a/third_party/polymer/v1_0/components/iron-ajax/iron-ajax.html
+++ b/third_party/polymer/v1_0/components/iron-ajax/iron-ajax.html
@@ -30,6 +30,8 @@ Note: The `params` attribute must be double quoted JSON.
You can trigger a request explicitly by calling `generateRequest` on the
element.
+
+@demo demo/index.html
-->
<script>
@@ -67,7 +69,9 @@ element.
/**
* An object that contains query parameters to be appended to the
- * specified `url` when generating a request.
+ * specified `url` when generating a request. If you wish to set the body
+ * content when making a POST request, you should use the `body` property
+ * instead.
*/
params: {
type: Object,
@@ -96,6 +100,9 @@ element.
* headers='{"X-Requested-With": "XMLHttpRequest"}'
* handle-as="json"
* last-response-changed="{{handleResponse}}"></iron-ajax>
+ *
+ * Note: setting a `Content-Type` header here will override the value
+ * specified by the `contentType` property of this element.
*/
headers: {
type: Object,
@@ -105,9 +112,9 @@ element.
},
/**
- * Content type to use when sending data. If the contenttype is set
- * and a `Content-Type` header is specified in the `headers` attribute,
- * the `headers` attribute value will take precedence.
+ * Content type to use when sending data. If the `contentType` property
+ * is set and a `Content-Type` header is specified in the `headers`
+ * property, the `headers` property value will take precedence.
*/
contentType: {
type: String,
@@ -207,7 +214,7 @@ element.
/**
* Will be set to the most recent response received by a request
* that originated from this iron-ajax element. The type of the response
- * is determined by the value of `handleas` at the time that the request
+ * is determined by the value of `handleAs` at the time that the request
* was generated.
*/
lastResponse: {
@@ -235,7 +242,7 @@ element.
notify: true,
readOnly: true,
value: function() {
- this._setActiveRequests([]);
+ return [];
}
},
@@ -251,23 +258,22 @@ element.
_boundHandleResponse: {
type: Function,
value: function() {
- return this.handleResponse.bind(this);
- }
- },
-
- _boundDiscardRequest: {
- type: Function,
- value: function() {
- return this.discardRequest.bind(this);
+ return this._handleResponse.bind(this);
}
}
},
observers: [
- 'requestOptionsChanged(url, method, params, headers,' +
+ '_requestOptionsChanged(url, method, params, headers,' +
'contentType, body, sync, handleAs, withCredentials, auto)'
],
+ /**
+ * The query string that should be appended to the `url`, serialized from
+ * the current value of `params`.
+ *
+ * @return {string}
+ */
get queryString () {
var queryParts = [];
var param;
@@ -287,6 +293,12 @@ element.
return queryParts.join('&');
},
+ /**
+ * The `url` with query string (if `params` are specified), suitable for
+ * providing to an `iron-request` instance.
+ *
+ * @return {string}
+ */
get requestUrl() {
var queryString = this.queryString;
@@ -297,9 +309,16 @@ element.
return this.url;
},
+ /**
+ * An object that maps header names to header values, first applying the
+ * the value of `Content-Type` and then overlaying the headers specified
+ * in the `headers` property.
+ *
+ * @return {Object}
+ */
get requestHeaders() {
var headers = {
- 'content-type': this.contentType
+ 'Content-Type': this.contentType
};
var header;
@@ -312,6 +331,19 @@ element.
return headers;
},
+ /**
+ * Request options suitable for generating an `iron-request` instance based
+ * on the current state of the `iron-ajax` instance's properties.
+ *
+ * @return {{
+ * url: string,
+ * method: (string|undefined),
+ * async: (boolean|undefined),
+ * body: (ArrayBuffer|ArrayBufferView|Blob|Document|FormData|null|string|undefined),
+ * headers: (Object|undefined),
+ * handleAs: (string|undefined),
+ * withCredentials: (boolean|undefined)}}
+ */
toRequestOptions: function() {
return {
url: this.requestUrl,
@@ -324,25 +356,13 @@ element.
};
},
- requestOptionsChanged: function() {
- this.debounce('generate-request', function() {
- if (!this.url && this.url !== '') {
- return;
- }
-
- if (this.auto) {
- this.generateRequest();
- }
- }, this.debounceDuration);
- },
-
/**
* Performs an AJAX request to the specified URL.
*
- * @method generateRequest
+ * @return {!IronRequestElement}
*/
generateRequest: function() {
- var request = document.createElement('iron-request');
+ var request = /** @type {!IronRequestElement} */ (document.createElement('iron-request'));
var requestOptions = this.toRequestOptions();
this.activeRequests.push(request);
@@ -350,14 +370,15 @@ element.
request.completes.then(
this._boundHandleResponse
).catch(
- this.handleError.bind(this, request)
+ this._handleError.bind(this, request)
).then(
- this._boundDiscardRequest
+ this._discardRequest.bind(this, request)
);
request.send(requestOptions);
this._setLastRequest(request);
+ this._setLoading(true);
this.fire('request', {
request: request,
@@ -367,12 +388,12 @@ element.
return request;
},
- handleResponse: function(request) {
+ _handleResponse: function(request) {
this._setLastResponse(request.response);
this.fire('response', request);
},
- handleError: function(request, error) {
+ _handleError: function(request, error) {
if (this.verbose) {
console.error(error);
}
@@ -387,12 +408,29 @@ element.
});
},
- discardRequest: function(request) {
+ _discardRequest: function(request) {
var requestIndex = this.activeRequests.indexOf(request);
- if (requestIndex > 0) {
+ if (requestIndex > -1) {
this.activeRequests.splice(requestIndex, 1);
}
- }
+
+ if (this.activeRequests.length === 0) {
+ this._setLoading(false);
+ }
+ },
+
+ _requestOptionsChanged: function() {
+ this.debounce('generate-request', function() {
+ if (!this.url && this.url !== '') {
+ return;
+ }
+
+ if (this.auto) {
+ this.generateRequest();
+ }
+ }, this.debounceDuration);
+ },
+
});
</script>

Powered by Google App Engine
This is Rietveld 408576698