Re: [sensors] Dependency on [DOM] due to inheriting from EventTarget

Take the one-time location request example from the existing spec 
(where a fresh location is required) and show how the Sensor API 
applies.  (Yes - I know this is not a Promise-based API, but it can be
 adapted to be Promise-based).  Note that there are no DOM 
dependenices in the example as far as I can tell.

<code>
 // Request a position. We only accept cached positions whose age is 
not
    // greater than 10 minutes. If the user agent does not have a 
fresh
    // enough cached position object, it will immediately invoke the 
error
    // callback.
    navigator.geolocation.getCurrentPosition(successCallback,
                                             errorCallback,
                                             {maximumAge:600000, 
timeout:0});

    function successCallback(position) {
      // By using the 'maximumAge' option above, the position
      // object is guaranteed to be at most 10 minutes old.
      // By using a 'timeout' of 0 milliseconds, if there is
      // no suitable cached position available, the user agent 
      // will asynchronously invoke the error callback with code
      // TIMEOUT and will not initiate a new position
      // acquisition process.
    }

    function errorCallback(error) {
      switch(error.code) {
        case error.TIMEOUT:
          // Quick fallback when no suitable cached position exists.
          doFallback();
          // Acquire a new position object.
          navigator.geolocation.getCurrentPosition(successCallback, 
errorCallback);
          break;
        case ... // treat the other error cases.
      };
    }

    function doFallback() {
      // No fresh enough cached position available.
      // Fallback to a default position.
    }
</code>

-- 
GitHub Notif of comment by gmandyam
See https://github.com/w3c/sensors/issues/21#issuecomment-111177707

Received on Thursday, 11 June 2015 15:42:56 UTC