Skip to content

Yet another subscription API #268

Open
@relu91

Description

@relu91

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 an ActionHandle
  • It still evokes TD basic operation verbs (i.e. observeProperty, onevent)

Cons

  • More verbose
  • Harder error handling for subscribe, unsubscribe, observe, and unobserve (i.e. you can't try {}catch{} but you have to use the EventHandler

What do you think? 🤔

Metadata

Metadata

Assignees

No one assigned

    Labels

    API-improvementSuggestions for changing the APIenhancementThoughts and ideas about possible improvements

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions