From 3ccf28e3130893714f2c56381f16b2a76c851e95 Mon Sep 17 00:00:00 2001 From: Alex Nicksay Date: Wed, 11 Feb 2015 21:51:18 -0500 Subject: [PATCH] Refactor spf.nav.request to use a dedicated class for chunking data. --- src/client/nav/request.js | 40 ++++++++++++++++++++++++++++++-------- src/client/nav/response.js | 1 + 2 files changed, 33 insertions(+), 8 deletions(-) diff --git a/src/client/nav/request.js b/src/client/nav/request.js index 2d978dc1..f871e812 100644 --- a/src/client/nav/request.js +++ b/src/client/nav/request.js @@ -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, @@ -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 */ @@ -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 @@ -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 */ @@ -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; diff --git a/src/client/nav/response.js b/src/client/nav/response.js index 869b4aae..3b6b1a80 100644 --- a/src/client/nav/response.js +++ b/src/client/nav/response.js @@ -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) {