rwaldron / sensors

Notes for Sensor API unification
3 stars 3 forks source link

Comparison to Tim Volodine's proposal #6

Open rwaldron opened 9 years ago

rwaldron commented 9 years ago

http://lists.w3.org/Archives/Public/public-device-apis/2014Sep/0024.html

As noted during the DAP call:

The item noted as a difference between "Sensor API Unification Sketch" (SAUS) and Tim's proposal is actually not a difference at all. Both versions initialize as null and would result in receiving the initial value payload at the same time. The real difference is that Tim's proposal doesn't allow user code to initialize a sensor object and do something with the reference (such as putting it into some sensor registry Map), whereas SAUS gives you the instance immediately, which allows the reference to be used in interesting ways before the initial payload is delivered.

rwaldron commented 9 years ago

Illustrative example (from Tim's proposal)


Example 2 (using requestAnimationFrame):

var sensor = null;
function updateFrame() {
  window.requestAnimationFrame(updateFrame);
  if (sensor)
    console.log(sensor.currentOrientation);
  // do something else
}

navigator.getDeviceOrientationSensor(“high”).then(
  function(orientationSensor){ sensor = orientationSensor; },
  function() { console.log("error"); });

window.requestAnimationFrame(updateFrame);

Would be written as:

var orientation = new sensors.Orientation({ frequency: 200 });

function updateFrame() {
  window.requestAnimationFrame(updateFrame);
  if (orientation.value)
    console.log(orientation.value);
  // do something else
}

window.requestAnimationFrame(updateFrame);
tobie commented 9 years ago

Moved to: https://github.com/w3c/sensors/issues/9