Open
Description
As requested here I wrote a new IDL for yet another variant of the subscription API. Please see the following Web IDL:
[Exposed=Window]
interface ConsumedThing {
/*... other methods */
ObservationHandle createObservation(DOMString name, optional InteractionOptions options = null);
SubscriptionHandle createSubscription(DOMString name, optional InteractionOptions options = null);
};
[Exposed=Window]
interface AffordanceHandle : EventTarget {
attribute EventHandler onerror;
};
[Exposed=Window]
interface SubscriptionHandle : AffordanceHandle {
undefined subscribeEvent();
undefined unsubscribeEvent();
attribute EventHandler onunsubscribeevent;
attribute EventHandler onevent;
attribute EventHandler onsubscribeevent;
};
[Exposed=Window]
interface ObservationHandle : AffordanceHandle {
undefined observeProperty();
undefined unobserveProperty();
attribute EventHandler onpropertychange;
attribute EventHandler onobserveproperty;
attribute EventHandler onunobserveproperty;
};
The design idea is to re-use as much as we can what is already out there. Therefore, here we are using EventTarget
and EventHandler
.
Pros
- Compliant to [Web Platform Design Principles]https://w3ctag.github.io/design-principles/#dont-invent-event-like
- no callback - promise duality
- In the future, we could adapt this pattern also for
actions
. For example, if we find a way to define long-standing actions in the TD, we could define anActionHandle
- It still evokes TD basic operation verbs (i.e.
observeProperty
,onevent
)
Cons
- More verbose
- Harder error handling for
subscribe
,unsubscribe
,observe
, andunobserve
(i.e. you can'ttry {}catch{}
but you have to use theEventHandler
What do you think? 🤔