Skip to content

Commit

Permalink
Modified _cache.response object to use the api.url plus the seria…
Browse files Browse the repository at this point in the history
…lized request string as a key to accommodate caching form requests to the same URL but with different input data.
  • Loading branch information
pklauzinski committed Apr 16, 2015
1 parent 9819009 commit 23bca39
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion bower.json
@@ -1,6 +1,6 @@
{
"name": "payload.js",
"version": "0.1.2",
"version": "0.1.3",
"homepage": "https://github.com/pklauzinski/payload",
"authors": [
{
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "payload.js",
"version": "0.1.2",
"version": "0.1.3",
"description": "HTML5-data-driven behavioral layer designed to interact intuitively with REST APIs from within SPAs (single-page-applications) and mobile apps.",
"main": "payload.js",
"scripts": {
Expand Down
14 changes: 7 additions & 7 deletions payload.js
Expand Up @@ -196,16 +196,15 @@
if (typeof(opts) === 'function') {
_options.apiCallback = opts;
} else if (typeof(opts) === 'object') {
$.extend(_options, opts);
_this.merge(opts);
} else if (typeof(opts) === 'string') {
_options.context = opts;
}
return _initialize();
};

this.merge = function(opts) {
$.extend(_options, opts);
return this;
return $.extend(_options, opts);
};

this.apiRequest = function($this) {
Expand Down Expand Up @@ -236,6 +235,7 @@
}
},
templateName = $this.attr(_dataPrefix + 'template') || $this.attr(_dataPrefix + 'partial'),
requestKey = api.url + $this.serialize(),
$selector, $loading, $load, html, templateData, params;

// Add the request payload to the template data under "request" namespace
Expand Down Expand Up @@ -285,12 +285,12 @@

_cacheView($this, api, templateName);

if (api.cacheResponse && _cache.response[api.url] && _cache.response[api.url].data && _cache.response[api.url].done) {
templateData = $.extend({}, _cache.response[api.url].data, api.templateData);
if (api.cacheResponse && _cache.response[requestKey] && _cache.response[requestKey].data && _cache.response[requestKey].done) {
templateData = $.extend({}, _cache.response[requestKey].data, api.templateData);
html = api.template ? api.template(templateData) : api.partial(templateData);
$selector.html(html);
_options.apiAfterRender(params);
_cache.response[api.url].done();
_cache.response[requestKey].done();
publishEvents([params]);
return;
}
Expand Down Expand Up @@ -360,7 +360,7 @@
}

if (api.cacheResponse) {
_cache.response[api.url] = {
_cache.response[requestKey] = {
data: templateData,
done: xhrDone
};
Expand Down
4 changes: 2 additions & 2 deletions payload.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 23bca39

Please sign in to comment.