Skip to content

Commit

Permalink
Merge pull request youtube#306 from nicksay/refactor-chunking-data
Browse files Browse the repository at this point in the history
Refactor spf.nav.request to use a dedicated class for chunking data.
  • Loading branch information
nicksay committed Mar 3, 2015
2 parents 3b286ad + 3ccf28e commit cd4db75
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 deletions.
40 changes: 32 additions & 8 deletions src/client/nav/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,7 @@ spf.nav.request.send = function(url, opt_options) {
headers['X-SPF-Request'] = headerId.replace('__type__', options.type);
headers['Accept'] = 'application/json';
}
var chunking = {
multipart: false,
extra: '',
complete: []
};
var chunking = new spf.nav.request.Chunking_();
var handleHeaders = spf.bind(spf.nav.request.handleHeadersFromXHR_, null,
url, chunking);
var handleChunk = spf.bind(spf.nav.request.handleChunkFromXHR_, null,
Expand Down Expand Up @@ -226,7 +222,7 @@ spf.nav.request.handleResponseFromCache_ = function(url, options, timing,
* See {@link #send}.
*
* @param {string} url The requested URL, without the SPF identifier.
* @param {Object} chunking Chunking status data.
* @param {spf.nav.request.Chunking_} chunking Chunking data.
* @param {XMLHttpRequest} xhr The XHR of the current request.
* @private
*/
Expand All @@ -245,7 +241,7 @@ spf.nav.request.handleHeadersFromXHR_ = function(url, chunking, xhr) {
*
* @param {string} url The requested URL, without the SPF identifier.
* @param {spf.nav.request.Options} options Configuration options
* @param {Object} chunking Chunking status data.
* @param {spf.nav.request.Chunking_} chunking Chunking data.
* @param {XMLHttpRequest} xhr The XHR of the current request.
* @param {string} chunk The current request chunk.
* @param {boolean=} opt_lastDitch Whether to parse the chunk as the final
Expand Down Expand Up @@ -291,7 +287,7 @@ spf.nav.request.handleChunkFromXHR_ = function(url, options, chunking,
* @param {string} url The requested URL, without the SPF identifier.
* @param {spf.nav.request.Options} options Configuration options
* @param {Object} timing Timing data.
* @param {Object} chunking Chunking status data.
* @param {spf.nav.request.Chunking_} chunking Chunking data.
* @param {XMLHttpRequest} xhr The XHR of the current request.
* @private
*/
Expand Down Expand Up @@ -535,6 +531,34 @@ spf.nav.request.setCacheObject_ = function(cacheKey, response, type) {
};


/**
* Container for holding data to track chunking for an SPF request.
*
* @constructor
* @struct
* @private
*/
spf.nav.request.Chunking_ = function() {
/**
* Whether the request is multipart.
* @type {boolean}
*/
this.multipart = false;
/**
* Any extra text from a previous chunk that was not successfully
* parsed on its own, usually due to an incomplete part split across
* chunk boundaries; combined with the text of a current chunk to complete.
* @type {string}
*/
this.extra = '';
/**
* Complete parts that have been successfully parsed.
* @type {!Array}
*/
this.complete = [];
};


if (spf.tracing.ENABLED) {
(function() {
var request = spf.nav.request;
Expand Down
1 change: 1 addition & 0 deletions src/client/nav/response.js
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,7 @@ spf.nav.response.getCurrentUrl_ = function() {
* @param {number} duration The animation duration.
* @param {boolean} reverse Whether this is a "back" animation.
* @constructor
* @struct
* @private
*/
spf.nav.response.Animation_ = function(el, html, cls, duration, reverse) {
Expand Down

0 comments on commit cd4db75

Please sign in to comment.