W3C home > Mailing lists > Public > public-webapps@w3.org > January to March 2010

Re: [DataCache] Updated Examples

From: Nikunj R. Mehta <nikunj.mehta@oracle.com>
Date: Fri, 1 Jan 2010 10:17:50 -0800
Cc: public-webapps@w3.org
Message-Id: <5E5F643D-FA10-49CE-96DA-422FE7361002@oracle.com>
To: Joseph Pecoraro <joepeck02@gmail.com>
Hi Joseph,

I have updated the examples with the new API. Please let me know if  
you see any issues now. Thanks a lot for the detailed feedback.

Nikunj
On Dec 10, 2009, at 1:02 PM, Joseph Pecoraro wrote:

> Again the examples seem out of date. I'll update the remaining  
> examples.  Sorry for not consolidating all of them into one email!
>
> - 4.1.1. Examples
> http://dev.w3.org/2006/webapi/DataCache/#examples
> The second example seems to be out of date for a number of reasons.
>
> [[
>  var uri = ...
>  var cache = window.openDataCache();
>  var local = function(request, response) {
>    response.statusCode = 200;
>    response.statusLine = 'HTTP/1.1 OK';
>    response.bodyText = ...
>    response.send();
>  };
>
>  window.navigator.registerOfflineHandler(uri, local);
>
>  var txn = cache.offlineTransaction(function(txn) {
>    txn.capture(uri, '', null, ['GET']);
>    txn.commit();
>  });
> ]]
>
> The issues I see are:
>
>  - cache.offlineTransaction does not return a value
>  - there is no commit() in an offlineTransaction
>  - response.X = ...; is not valid, use the IDL's setX functions
>  - statusCode and statusLine/Text are both set with the IDL's  
> setStatus()
>
> I would have expected the example to look more like the following:
>
> ----
>  var uri = ...
>  var cache = window.openDataCache();
>  var local = function(request, response) {
>    response.setStatus(200, 'HTTP/1.1 OK');
>    repsonse.setResponseText(...);
>    response.send();
>  };
>
>  window.navigator.registerOfflineHandler(uri, local);
>
>  cache.offlineTransaction(function(txn) {
>    txn.capture(uri, '', null, ['GET']);
>  });
> ----
>
> Also "localServer", "interceptor", or "intercept" (used in a later  
> example) may be better names than "local" for the interceptor  
> function. But that is more of a style issue.
>
>
>
> - 4.1.1. Examples
> http://dev.w3.org/2006/webapi/DataCache/#examples
> The third example seems to be out of date for a number of reasons.
>
> [[
>  cache = window.openDataCache();
>  var intercept = function(request, response) {
>    if (...) {
>      // validation fails
>      response.setStatus(400, 'HTTP/1.1 Bad Request');
>      response.send();
>      return;
>    }
>    cache.offlineTransaction(function(txn) {
>      txn.oncommitted = function() {
>        response.bodyText = request.bodyText;
>        response.headers['Content-Type'] = type;
>        response.statusCode = 200;
>        response.statusLine = 'HTTP/1.1 OK';
>        response.send();
>      });
>      txn.capture(request.targetURL, request.bodyText,  
> request.headers['Content-Type']);
>      txn.commit();
>    });
>  };
>
>  var review = function(request, response) {
>    cache.offlineTransaction(function(txn) {
>      txn.capture(request.targetURL, response.bodyText,  
> response.headers['Content-Type']);
>      txn.commit();
>    });
>  };
>
>  window.navigator.registerOfflineHandler(uri, intercept, review);
> ]]
>
>
> The issues I see are:
>
>  - use `var` for the cache variable in the Window's scope
>  - `uri` variable is not declared in the Window's scope, only the  
> Worker's
>  - `type` variable is not declared at all, I'll leave that blank, as  
> I don't understand the example's intent
>  - there is no commit() in an offlineTransaction
>  - response.X = ...; is not valid, use the IDL's setX functions  
> (like at the top)
>  - request.targetURL should be request.target
>  - the surrounding text says the interceptor is called on PUT, but  
> no dynamic method is provided
>
> I would have expected the example to look more like the following:
>
> ----
>  var uri = ...
>  var cache = window.openDataCache();
>  var intercept = function(request, response) {
>    if (...) {
>      // validation fails
>      response.setStatus(400, 'HTTP/1.1 Bad Request');
>      response.send();
>      return;
>    }
>    cache.offlineTransaction(function(txn) {
>      txn.oncommitted = function() {
>        response.setStatus(200, 'HTTP/1.1 OK');
>        response.setResponseText(request.bodyText);
>        response.setResponseHeader('Content-Type', ...);
>        response.send();
>      });
>      txn.capture(request.target, request.bodyText,  
> request.headers['Content-Type'], ['PUT']);
>    });
>  };
>
>  var review = function(request, response) {
>    cache.offlineTransaction(function(txn) {
>      txn.capture(request.target, response.bodyText,  
> response.headers['Content-Type'], ['PUT']);
>    });
>  };
>
>  window.navigator.registerOfflineHandler(uri, intercept, review);
> ----

Nikunj Mehta
http://blog.o-micron.com
Received on Friday, 1 January 2010 18:19:19 GMT

This archive was generated by hypermail 2.3.1 : Tuesday, 26 March 2013 18:49:36 GMT