Skip to content

Commit

Permalink
Change names to be more intuitive
Browse files Browse the repository at this point in the history
  • Loading branch information
wycats committed May 12, 2010
1 parent ba822d4 commit d3bef9b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
4 changes: 2 additions & 2 deletions README.textile
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ jQuery.retrieveJSON("/url", {data: "toSend"}, function(json, status, data) {

Returning false from the callback when the status is @cached@ will cause jQuery Offline to skip the Ajax request. You can use this if you don't want to refresh the content if there is local content available.

If the contents come from the cache, the third parameter will be an object containing the time that jQuery Offline originally cached the content: <code>{ time: originalTime }</code>.
If the contents come from the cache, the third parameter will be an object containing the time that jQuery Offline originally cached the content: <code>{ cachedAt: originalTime }</code>.

If the Ajax request was made after a successful hit from the cache, jQuery Offline will make the third parameter to the function <code>{ time: originalTime, cacheTime: timeRetrieved }</code>. The @originalTime@ is the original time that the item was put into the cache. The @timeRetrieved@ is the time that the data was originally retrieved from the cache (in this session). You might use this third parameter to alert the user that a change is about to happen, if such a change would be particularly jarring.
If the Ajax request was made after a successful hit from the cache, jQuery Offline will make the third parameter to the function <code>{ cachedAt: originalTime, retrievedAt: timeRetrieved }</code>. The @originalTime@ is the original time that the item was put into the cache. The @timeRetrieved@ is the time that the data was originally retrieved from the cache (in this session). You might use this third parameter to alert the user that a change is about to happen, if such a change would be particularly jarring.

Note that this third parameter is also supplied for a cache hit; if you want to determine whether a particular response is a follow-up to a cache hit, use: <code>if( status == "success" && data )</code>.

Expand Down
4 changes: 2 additions & 2 deletions lib/jquery.offline.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,15 @@
// retrieved from the cache. With this information,
// users of jQuery Offline can provide the user
// with improved feedback if the lag is large
var data = text && { time: date, cacheTime: retrieveDate };
var data = text && { cachedAt: date, retrievedAt: retrieveDate };
fn(json, status, data);
});
}

// If there is anything in the cache, call the callback
// right away, with the "cached" status string
if( text ) {
var response = fn( $.parseJSON(text), "cached", { time: date } );
var response = fn( $.parseJSON(text), "cached", { cachedAt: date } );
if( response === false ) return false;
}

Expand Down
7 changes: 4 additions & 3 deletions public/tests/test.offline.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ var baseTest = function( next, data, obj ) {
$.retrieveJSON("/ajax/app", data, function( json, text, flag ) {
if(text == "success") {
if(obj.successFlag) {
ok( flag && flag.time, "a follow-up request should have a flag" )
ok( flag && flag.cachedAt, "a follow-up request should have the cache time" );
ok( flag && flag.retrievedAt, "a follow-up request should have the retrieve time" );
}

var countSucc = (count || 1) + 1;
Expand All @@ -39,7 +40,7 @@ var baseTest = function( next, data, obj ) {
else next();
} else if(text == "cached") {
if(obj.cachedFlag) {
ok( flag && flag.time, "a cache hit should have a flag" )
ok( flag && flag.cachedAt, "a cache hit should have the cache time" )
}

cached = text;
Expand All @@ -62,7 +63,7 @@ if( $.support.localStorage ) {
});
});

asyncTest("the second time, it gets a flag back", function() {
asyncTest("the second time, it gets additional data in the callback", function() {
$(document).dequeue().queue(function(next) {
setup(next);
}).queue(function(next) {
Expand Down

0 comments on commit d3bef9b

Please sign in to comment.