Skip to content

Commit

Permalink
Begin key migration: css -> head, html -> body, js -> foot. Reserve a…
Browse files Browse the repository at this point in the history
… new key for arbitrary client data of any type in the response (data).

[git-p4: change = 69739490]
  • Loading branch information
nicksay committed Jun 23, 2014
1 parent 4e933a8 commit 5186b2b
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 32 deletions.
78 changes: 55 additions & 23 deletions src/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,46 +20,78 @@ var spf = {};
spf.SingleResponse;


/**
* Map of Element IDs to maps of attibute names to values for the Elements.
* @type {Object.<string, Object.<string, string>>|undefined}
*/
spf.SingleResponse.prototype.attr;


/**
* Map of Element IDs to HTML strings containing content of the Elements. The
* content may contain script and/or style tags to be executed or installed.
* @type {Object.<string, string>|undefined}
*/
spf.SingleResponse.prototype.body;


/**
* String of the type of caching to use for this response.
* @type {string|undefined}
*/
spf.SingleResponse.prototype.cacheType;


/**
* HTML string containing <link> and <style> tags of CSS to install.
* @deprecated Use {@code head} instead.
* @type {string|undefined}
*/
spf.SingleResponse.prototype.css;


/**
* Map of Element IDs to HTML strings containing content of the Elements.
* @type {Object.<string, string>|undefined}
* Reserved for client data of any type.
* @type {*|undefined}
*/
spf.SingleResponse.prototype.html;
spf.SingleResponse.prototype.data;


/**
* Map of Element IDs to maps of attibute names to values for the Elements.
* @type {Object.<string, Object.<string, string>>|undefined}
* HTML string containing CSS and/or JS tags to execute or install.
* @type {string|undefined}
*/
spf.SingleResponse.prototype.attr;
spf.SingleResponse.prototype.head;


/**
* HTML string containing <script> tags of JS to execute.
* Map of Element IDs to HTML strings containing content of the Elements.
* @deprecated Use {@code body} instead.
* @type {Object.<string, string>|undefined}
*/
spf.SingleResponse.prototype.html;


/**
* HTML string containing JS and/or CSS tags to execute or install.
* @type {string|undefined}
*/
spf.SingleResponse.prototype.js;
spf.SingleResponse.prototype.foot;


/**
* String of the new Document title.
* HTML string containing <script> tags of JS to execute.
* @deprecated Use {@code foot} instead.
* @type {string|undefined}
*/
spf.SingleResponse.prototype.title;
spf.SingleResponse.prototype.js;


/**
* String of the type of caching to use for this response.
* String of a URL to request instead.
* @type {string|undefined}
*/
spf.SingleResponse.prototype.cacheType;
spf.SingleResponse.prototype.redirect;


/**
Expand All @@ -70,18 +102,18 @@ spf.SingleResponse.prototype.timing;


/**
* String of the correct URL for the current request. This will replace the
* current URL in history.
* String of the new Document title.
* @type {string|undefined}
*/
spf.SingleResponse.prototype.url;
spf.SingleResponse.prototype.title;


/**
* String of a URL to request instead.
* String of the correct URL for the current request. This will replace the
* current URL in history.
* @type {string|undefined}
*/
spf.SingleResponse.prototype.redirect;
spf.SingleResponse.prototype.url;


/**
Expand All @@ -92,17 +124,17 @@ spf.MultipartResponse;


/**
* List of response objects.
* @type {Array.<spf.SingleResponse>|undefined}
* String of the type of caching to use for this response.
* @type {string|undefined}
*/
spf.MultipartResponse.prototype.parts;
spf.MultipartResponse.prototype.cacheType;


/**
* String of the type of caching to use for this response.
* @type {string|undefined}
* List of response objects.
* @type {Array.<spf.SingleResponse>|undefined}
*/
spf.MultipartResponse.prototype.cacheType;
spf.MultipartResponse.prototype.parts;


/**
Expand Down
21 changes: 12 additions & 9 deletions src/client/nav/response.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,13 @@ spf.nav.response.process = function(url, response, opt_callback, opt_navigate,
}

// Install page styles (single task), if needed.
if (response['css']) {
// TODO(nicksay): Remove "css" key.
if (response['head'] || response['css']) {
fn = spf.bind(function(css, timing) {
spf.nav.response.installStyles_(spf.nav.response.parseStyles_(css));
timing['spfProcessCss'] = spf.now();
spf.debug.debug(' process task done: css');
}, null, response['css'], response['timing']);
}, null, (response['head'] || response['css']), response['timing']);
num = spf.tasks.add(key, fn);
spf.debug.debug(' process task queued: css', num);
}
Expand Down Expand Up @@ -296,7 +297,7 @@ spf.nav.response.process = function(url, response, opt_callback, opt_navigate,
var numFragments = numAfterFragments - numBeforeFragments;

// Install page scripts (single task), if needed.
if (response['js']) {
if (response['foot'] || response['js']) {
fn = spf.bind(function(js, timing, numFragments) {
// Use the page scripts task as a signal that the content is updated,
// only recording the content completion time if fragments were processed.
Expand All @@ -311,7 +312,8 @@ spf.nav.response.process = function(url, response, opt_callback, opt_navigate,
spf.debug.debug(' process task done: js');
spf.tasks.resume(key, sync); // Resume main queue after JS.
});
}, null, response['js'], response['timing'], numFragments);
}, null, (response['foot'] || response['js']), response['timing'],
numFragments);
num = spf.tasks.add(key, fn);
spf.debug.debug(' process task queued: js', num);
} else if (numFragments) {
Expand Down Expand Up @@ -358,17 +360,18 @@ spf.nav.response.preprocess = function(url, response, opt_callback) {
var fn;

// Preinstall page styles (single task), if needed.
if (response['css']) {
if (response['head'] || response['css']) {
fn = spf.bind(function(css) {
spf.nav.response.preinstallStyles_(spf.nav.response.parseStyles_(css));
spf.debug.debug(' preprocess task done: css');
}, null, response['css']);
}, null, (response['head'] || response['css']));
spf.tasks.add(key, fn);
spf.debug.debug(' preprocess task queued: css');
}

// Preinstall fragment scripts (one task per fragment).
var fragments = response['html'] || {};
// TODO(nicksay): Remove "html" key.
var fragments = response['body'] || response['html'] || {};
for (var id in fragments) {
if (fragments[id]) {
fn = spf.bind(function(id, html) {
Expand All @@ -385,13 +388,13 @@ spf.nav.response.preprocess = function(url, response, opt_callback) {
}

// Preinstall page scripts (single task).
if (response['js']) {
if (response['foot'] || response['js']) {
fn = spf.bind(function(js) {
// NOTE: Suspending the queue is not needed since the JS is not
// actually executed and other tasks don't have to wait.
spf.nav.response.preinstallScripts_(spf.nav.response.parseScripts_(js));
spf.debug.debug(' preprocess task done: js');
}, null, response['js']);
}, null, (response['foot'] || response['js']));
spf.tasks.add(key, fn);
spf.debug.debug(' preprocess task queued: js');
}
Expand Down

0 comments on commit 5186b2b

Please sign in to comment.