Skip to content

Commit

Permalink
General Cleanup. Minor fixes as well.
Browse files Browse the repository at this point in the history
- no longer reset the cache on offline transition as the queue is only
  modified when offline, so it shouldn't matter.
- no need to store a blank cache result for the apiURI. In fact, I
  don't even think it is called...
- spelling errors, whitespace, etc.
  • Loading branch information
JosephPecoraro committed Jan 12, 2010
1 parent 80692ee commit df56d06
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions sample/notes/js/offlineHandlers.js
Expand Up @@ -200,8 +200,11 @@

var cache = window.openDataCache();
cache.offlineTransaction(function(tx) {
tx.capture(apiURI, null, null, dynamicMethods);
tx.commit();
// Drawback of DataCache: check if an item is cached.
try { tx.getItem(apiURI, function(){ tx.commit(); }); } catch (e) {
tx.capture(apiURI, null, null, dynamicMethods);
tx.commit();
}
});


Expand Down Expand Up @@ -229,7 +232,7 @@
return;
}

// Advnaced Handling
// Advanced Handling
var handler = interceptor[request.method.toUpperCase()];
if (handler) {
handler(request, response);
Expand Down Expand Up @@ -443,29 +446,25 @@
// Synchronization
// -------------------

document.addEventListener('now-offline', function() {
queue.reset();
}, false);

document.addEventListener('now-online', function() {
var itemCount = 0;
queue.process(itemCallback, successCallback);

function itemCallback(uri, method) {
console.log('itemCallback', uri, method);
console.log('processing item', uri, method);
itemCount++;
var tx = cache.transactionSync();
var item = tx.cache.getItem(uri); // FIXME: Private API, needed because its synchronous...
var xhr = new XMLHttpRequest();
xhr.open(method, uri, false); // Synchronous for testing
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xhr.setRequestHeader('X-Bypass-DataCache', 'true'); // purposely avoid the DataCache!
xhr.onload = function() { console.log('Xsuccess', xhr, xhr.responseText);
xhr.onload = function() { // DEBUG: console.log('Xsuccess', xhr, xhr.responseText);
if (method === 'POST' && xhr.responseText.length > 0) {
updateTwitterBoxId(item.body, xhr.responseText);
}
}
xhr.onerror = function() { console.log('Xerror', xhr, xhr.responseText); } // FIXME: in case of sync error
xhr.onerror = function() { /* DEBUG: console.log('Xerror', xhr, xhr.responseText); */ }
xhr.send(item.body);
}

Expand Down

0 comments on commit df56d06

Please sign in to comment.