w3c / sensors

Generic Sensor API
https://www.w3.org/TR/generic-sensor/
Other
127 stars 59 forks source link

Should SensorReadingEvent carry reading payload? #103

Closed timvolodine closed 8 years ago

timvolodine commented 8 years ago

since the sensor reading can be obtained from Sensor directly maybe the SensorReadingEvent doesn't need to carry that information and only signal that reading has changed..

tobie commented 8 years ago

True. What's the reasoning behind that? Simplifying the API?

timvolodine commented 8 years ago

Yes, I think the implementation will be much simpler, especially because we can derive sensors from the general interface. And also if the amount of data is substantial, but that's probably not really an issue for mems sensors..

tobie commented 8 years ago

I'm warming up to this idea, as long as it doesn't hurt developer experience.

rwaldron commented 8 years ago

From experience, devs want to be able to things like this:

sensorA.on("change", event => someGenericDataStoringOperation(event));
sensorB.on("change", event => someGenericDataStoringOperation(event));

TBH, I think that's completely uncool practice, but people like doing things that I don't necessarily like to do.

tobie commented 8 years ago

You should just be able to do this instead, no:

sensorA.onchange = _ => someGenericDataStoringOperation(this.reading);
sensorB.onchange = _ => someGenericDataStoringOperation(this.reading);
rwaldron commented 8 years ago
sensorB.onchange = event => someGenericDataStoringOperation(this.reading);

Wrong this ;)

tobie commented 8 years ago

Yeah, that was precisely in the back of my mind from the very start of this conversation. I need to dig deeper into fat arrow scoping. :-/

So it would be either:

sensorA.onchange = _ => someGenericDataStoringOperation(sensorA.reading);
sensorB.onchange = _ => someGenericDataStoringOperation(sensorB.reading);

or:

sensorA.onchange = function() { someGenericDataStoringOperation(this.reading); };
sensorB.onchange = function() { someGenericDataStoringOperation(this.reading); };
timvolodine commented 8 years ago

yeah so they could just pass sensorA or B to the function no? also if a user only needs a subset of data it makes more sense instead of propagating the whole set every time an event happens.

zolkis commented 8 years ago

This is quite an evergreen topic and pops up with data APIs every now and then. For my taste a vanilla event and data fetcher is better for large data sets, and a specialized event is simpler and better for the generic sensor use case (small amount of data coming at high possible rate):

So what I would do (which is not necessarily what this spec should do, but consider it):

tobie commented 8 years ago

Seems there are advocates of both solutions, here. Worth considering the advantages and disadvantages of both and maybe continuing to offer both.

@zolkis, am I right in my understanding of your suggestion that you're advocating for the data to be directly on the event object itself rather than in the reading property?

zolkis commented 8 years ago

@zolkis, am I right in my understanding of your suggestion that you're advocating for the data to be directly on the event object itself rather than in the reading property?

For sensors, yes.

tobie commented 8 years ago

@zolkis, let me be more precise:

Am I right in my understanding of your suggestion that you're advocating for the data to be directly on the event object itself rather than in the reading property of the event? So: event.latitude rather than event.reading.latitude?

zolkis commented 8 years ago

I'd prefer the latter. Since the sensor (type) defines its data interface, I would use a separate property for that, like event.data.latitude or event.reading.latitude.

In most cases a property bag would be enough, but it may even be a fetching interface if needed, depending on the sensor, like event.data.nextChunk().

I've been experimenting with I/O APIs that support configuring the read process with min / max bit length for a reading, and min / max frequency of reading, which influences how data is exposed on the data fetching interface. For this type of use I think Tim's suggestion to expose a reader and use vanilla events would work better, with the reservation that then Sensor should be an interface and not a base class (in Java sense), so instead of subclassing, one could say

interface MySensor { ... };
MySensor implements Sensor;

instead of

interface MySensor: Sensor { ... };

However, with this design, and for this type of sensor use case I would recommend exposing the data on the sensor as a separate object property.

dontcallmedom commented 8 years ago

Decided at TPAC: RESOLUTION: remove event payload from SensorReadingEvent