-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
API improvement: track TD (interactions) #96
Comments
Following recent discussions, looks like the best way to represent Thing interactions is using (interface) objects for Property, Action and Event. A Thing could be represented the following way in the Scripting API. interface ConsumedThing {
readonly attribute DOMString name;
readonly attribute USVString baseURL;
getter sequence<DOMString> ("@context");
getter sequence<DOMString> ("@type");
readonly attribute sequence<Dictionary> security; // not defined yet
readonly attribute maplike<DOMString, Property> properties;
readonly attribute maplike<DOMString, Actions> actions;
readonly attribute maplike<DOMString, Event> events;
};
[NoInterfaceObject]
interface Interaction { // abstract class
readonly attribute DOMString name;
readonly attribute sequence<WebLink> links; // interaction endpoint
getter sequence<DOMString> ("@type");
};
interface ThingProperty: Interaction {
readonly attribute DataSchema schema;
readonly attribute boolean writable;
readonly attribute boolean observable;
Promise<any> get();
Promise set(any value);
Observable<any> observe(); // may allow options later
};
interface ThingAction: Interaction {
readonly attribute DataSchema inputSchema;
readonly attribute DataSchema outputSchema;
Promise<any> run(any parameters);
};
interface ThingEvent: Interaction {
readonly attribute DataSchema schema;
readonly any data;
};
ThingEvent implements Observable;
typedef JSON DataSchema;
dictionary WebLink {
required USVString href;
USVString mediaType;
DOMString relationType;
DOMString anchor;
}; The interface for ExposedThing will be addressed later, but would not change much except for adapting to the changes above. |
@danielpeintner @knimura @mkovatsc any opinions? Some explanation on let t = await thing.properties["temperature"].get(); or await thing.properties.temperature.set(25); For Events, one could say let subscription = thing.events["temperaturechange"]
.subscribe( t => { console.log("T = " + t); }); |
The direction looks good to me! (I wrote similar goal examples in w3c/wot-thing-description#87 (comment) except that I played with I have to look deeper into |
Actually I made a change to use
About hiding semantic annotations (mostly |
Yes, when looking at this now, get and set look fine. If only we could quickly find why we changed from get/set to read/write back then... could avoid going in circles :)
Okay, so just what one would expect for JavaScript. The @ prefix would nicely omit semantic annotations in autocomplete when using the dot notation, but they are still accessible.. |
So from what I understood we can compare
with what we used to have so far
This is a nice and easy mapping. I assume some more features such as What I am not fully sure of is wether this API improvement is meant to be something additional (more or less syntactic sugar) or whether the old API is meant to fully disappear. I assume one API is better than many. Moreover, I wonder how would the Note: I also think we need to agree on in the group what languages we plan to support with the Scripting API. We currently focus on JavaScript with some eyes on TypeScript. We identified that nice JS code like |
To my understanding, this is an new iteration to be discussed in Prague, which would fit directly to the simplified, JSON-like TD. |
Yes, this issue/proposal is to be discussed in the next F2F. |
@zolkis I think we need to prepare this based on the Simplified TD proposal, as it would allow Thing software object instances to directly correspond to the TD structure allowing for very transparent introspection (colloquially speaking, a Thing without handler code would be basically equal to a |
Sounds good. |
Handled by #113. |
This comment will be updated with the TD spec, which exposes the following structure for a Thing (translated to "raw" WebIDL):
This issue serves as discussion for a scripting API that best represents this structure, including introspection.
The text was updated successfully, but these errors were encountered: