- From: Crofts, Adam <acrofts1@jaguarlandrover.com>
- Date: Fri, 6 Nov 2015 16:41:19 +0000
- To: public-automotive <public-automotive@w3.org>
- Message-ID: <CAA-gn2m2QPqgtQeh6DqSLwM6LEyB1bsdfxi52X334be_jS+NCg@mail.gmail.com>
Hi All, After discussions with the Generic Sensor API Working Group at the TPAC last week we have proposed a refactoring of the data access methods in the Vehicle Information Access API to utilise EventHandlers instead of the current pub/sub model. This proposal is with the intention to make the API more usable and intuitive to a web developer, so I would be interested to hear your opinions on the potential change. Current Vehicle Information Access API using pub/sub - http://rawgit.com/w3c/automotive/master/vehicle_data/vehicle_spec.html GitHub Proposal using EventHandlers - https://github.com/w3c/automotive/issues/72 Tobie Langel from the Generic Sensor API WG has commented proposing a number of potential implementations, which I have copied below. The existing API also does not allow for subscriptions to individual attributes within an interface, also detailed in the GitHub discussion, so this technique will also allow for such an implementation. I look forward to hearing your opinions. Kind regards, Adam 1. Creating dedicated event handlers for each properties: interface VehicleSignal : Vehicle { Promise set (object value); attribute EventHandler onerror; attribute Zone? zone; }; interface Trip : VehicleSignal { attribute EventHandler ondistancechange; attribute EventHandler onaveragespeedchange; attribute EventHandler onfuelconsumptionchange; }; Which would let you write code like: vehicle.trip.onaveragespeedchange = function(e) { // do stuff. }; 2. creating dedicated generic observers: [Constructor(DOMString type, Zone zone), Exposed=(Window,Worker)]interface VehicleSignal : Vehicle { Promise set (object value); attribute EventHandler ondata; attribute EventHandler onchange; attribute EventHandler onerror; attribute DOMString type; // or Enum attribute Zone zone; }; interface Trip { attribute VehicleSignal distance; attribute VehicleSignal averageSpeed; attribute VehicleSignal fuelConsumption; }; Which would let you write code like: vehicle.trip.averageSpeed.onchange = function(e) { // do stuff. }; 3. creating dedicated specific observers: [Constructor(Zone zone), Exposed=(Window,Worker)]interface VehicleSignal : Vehicle { attribute EventHandler onerror; attribute Zone zone; }; interface VehicleDistanceSignal : VehicleSignal { // specific stuff }; interface VehicleAverageSpeedSignal : VehicleSignal { // specific stuff EventHandler onaveragespeedchange }; interface VehicleFuelConsumptionSignal : VehicleSignal { // specific stuff }; interface Trip { attribute VehicleDistanceSignal distance; attribute VehicleAverageSpeedSignal averageSpeed; attribute VehicleFuelConsumptionSignal fuelConsumption; }; Which would let you write code like: vehicle.trip.averageSpeed.onaveragespeedchange = function(e) { // do stuff. }; I believe that the last solution is what you'll end up ultimately gravitating towards. The generalizations you're trying to make to go for solution 2 will end up creating lots of edge cases you'll have to handle in prose and will create a poor overall developer experience. Solution 1 could be an interesting proposal, but I'm concerned it will make for an overall more complex and less flexible spec. -- *Adam C*rofts *MEng (Hons) MIET* Connected Infotainment Electrical Engineering Tel: +44 (0) 1926 921607 | 87311607 Mob: +44 (0) 7790 094350 Desk: G03/054, Building 523, Gaydon Mail Drop: G/26/3, Building 523, Gaydon Jaguar Land Rover Limited Registered Office: Abbey Road, Whitley, Coventry CV3 4LF Registered in England No: 1672070 This e-mail and any attachments contain confidential information for a specific individual and purpose. The information is private and privileged and intended solely for the use of the individual to whom it is addressed. If you are not the intended recipient, please e-mail us immediately. We apologise for any inconvenience caused but you are hereby notified that any disclosure, copying or distribution or the taking of any action in reliance on the information contained herein is strictly prohibited.
Received on Friday, 6 November 2015 16:41:50 UTC