-
Notifications
You must be signed in to change notification settings - Fork 28
Update the API according to discussion in #82 and #78 #86
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
Conversation
Signed-off-by: Zoltan Kis <[email protected]>
Signed-off-by: Zoltan Kis <[email protected]>
…posedThings. See also w3c#64. Signed-off-by: Zoltan Kis <[email protected]>
…eDefinition, request handlers for ExposedThing Signed-off-by: Zoltan Kis <[email protected]>
This PR introduces many completely new concepts that conflict with our long-lived discussion in #82, e.g.:
Is this to be changed as part of the work-in-progress, or are you proposing this now? |
Signed-off-by: Zoltan Kis <[email protected]>
We have addressed these points during the call. Now the proposal is more or less clean. The reasons for change are the following.
Also, see #64 for reasoning on consume/produce pair of words. While I think "expose()" made sense when the returned object was ready to be started, this method is really just a factory for a half-baked exposed Thing. Perhaps we could rename ExposedThing, but we don't need to. This method could also be just a constructor for an ExposedThing instead of a factory method. That would be more clear, and also would permit better separation/grouping in the spec.
I am not sure what do you mean here. Perhaps 6. explains.
In fact, part of these changes are small, part of them are needed. The question is consistency, usability and alignment with the TD spec and other APIs. I believe this version is better (if not perfect) in that sense. |
Mainly, we must not repeat the mishap of a broken (FP)WD, which was caused by ad hoc changes and introduction of unfinished, unconsolidated concepts. So why introduce these changes now and independently? The conclusion in the call was to write up what was discussed there.
|
@knimura and @danielpeintner please comment, so we can have a prepared call on Monday. |
The remaining question is whether should we rather make it a constructor to ExposedThing instead of a factory method with disputed naming? Then we avoid the terminology discussion and have cleaner, more JS-like definition to create local ExposedThing objects. The only reason to keep the factory method would be if we wanted to create remote Things, but that is no longer a use case, as it can be done as a service. The WebIDL would look like this: [Constructor(optional ThingModel model)]
interface ExposedThing {
//...
};
I am also fine with removing ConsumedThing from the models. I was just thinking it could offer significant optimization opportunity when we want to re-expose a consumed thing, i.e. we don't need to fetch/consume a TD, then read the serialized form from the consumed thing and feed it to the ExposedThing factory that will parse it again. However, we could add this later, eventually.
I am also fine with ExposedThing extending ConsumedThing, but we should be clear about the use cases.
After playing with examples, I am pretty convinced now that this is the best way to go. I should add more example code to the spec. |
|
…dThing. Signed-off-by: Zoltan Kis <[email protected]>
No issues with the name change.
Not clear the definition of ThingModel. I have no problem with ThingTemplate, if the definition of ThingTemplate is the complete subset of TD but just excluding binding information from it.
I agree with ExposedThing extending ConsumedThing, because ExposedThing should have the same function as ConsumedThing. But maybe difficult to understand the notion of "inheriting client API of local thing is part of ExposedThing(ServerAPI)", so showing the use case would be needed.
Totally agree.
Agree. If ThingTemplate is subset of TD and ExposedThing is created from ThingTemplate, both removeProperty and addProperty must be called to setting handler. If we feel that going back to the initial API, introducing UpdateProperty may be one of the solution to avoid onRetrieveProperty or so. |
…dlers. Signed-off-by: Zoltan Kis <[email protected]>
A Thing model (the term was taken from #64) is either a ThingTemplate (dictionary) or a ThingDescription (string). I have changed back to |
Signed-off-by: Zoltan Kis <[email protected]>
…nd dictionary members. Signed-off-by: Zoltan Kis <[email protected]>
As discussed on the call, on request by @knimura , added a short informal section for Observables, and on request by @danielpeintner , removed optionality from some of the arguments and dictionary members. |
As discussed in the call, added explanations on how handlers are working/implemented on ExposedThing. @mjkoster please take a look. |
Signed-off-by: Zoltan Kis <[email protected]>
ed6e690
to
c69afdf
Compare
One comment/question: I noticed that PropertyWriteHandler gets only the new value. We used to have "oldValue" and "newValue". Any rational for this change? |
WiP is removed, proof-reading can start. |
This is a quite strong concept change. As I mentioned, we had a reactive programming pattern before, which has at least two benefits:
Such a change must be explicitly discussed and is not fit for Prague. |
There is an editor's Note in the spec stating:
So your use case seems to be solved. |
We are discussing server side (ExposedThing) -- the client (ConsumedThing) has nothing to do with these handlers. |
Okay, I see you already removed "client" from that note -- thanks! ;) Have you checked that the handler code has always the right reference to the ExposedThing object to call |
Of course the handler code has the right reference to the ExposedThing object. thing.setPropertyWriteHandler(value => {
thing.readProperty(propertyName).then(oldValue => {
// put handler code here
if (oldValue < 5) {
// update to value
gpio.port.write(0x02, value);
}
});
}, propertyName); |
…ons. Removed duplicated statements. Signed-off-by: Zoltan Kis <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please find comments I got when doing a first read through. In general I think it is fine to merge and keep fixing/updating.
index.html
Outdated
let discoveryFilter = { | ||
method: "directory", | ||
url: "http://directory.wotservice.org" | ||
}; | ||
let subscription = wot.discover(discoveryFilter).subscribe( | ||
thing => { console.log("Found Thing " + thing.url); }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A ConsumedThing does not have url field anymore. Example needs to be change to thing.name
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
index.html
Outdated
from a <a>Thing Description</a>, then adding request handlers; | ||
</li> | ||
<li> | ||
from an existing <a>ConsumedThing</a> object, based on its <a>Thing Description</a>, then adding request handlers. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The third option is a special case of option 2. Hence I propose to remove option 3 and change option 2 to
from a Thing Description (possibly also retrieved from a ConsumedThing), then adding request handlers;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
USVString url; | ||
Dictionary description; | ||
USVString query; | ||
sequence<Dictionary> constraints; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The AND and OR relationship for constraints seems to be very powerful but also complex at first. Moreover, the link to "the semantic metadata" in its description is very fuzzy. As I understand it, the key of the key-value pair is a reference to SemanticType
. If so we might want to add an example.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See Example 4. ("protocol" is made up for the example)
index.html
Outdated
let subscription = wot.discover({ method: "nearby", description: {protocol: "BLE4.2"} }).subscribe( | ||
<pre class="example" title="Same as above but with different Observable syntax"> | ||
let subscription = wot.discover({ method: "local" }).subscribe({ | ||
next: thing => { console.log("Found local Thing " + thing.url); }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See before: A ConsumedThing does not have url field anymore. Example needs to be change to thing.name
index.html
Outdated
let subscription = wot.discover({ | ||
method: "nearby", | ||
constraints: [{ protocol: "BLE-4.2" }, { protocol: "NFC"}] | ||
}).subscribe( | ||
thing => { console.log("Found nearby Thing " + thing.url); }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See before: A ConsumedThing does not have url field anymore. Example needs to be change to thing.name
index.html
Outdated
dictionary ThingPropertyInit: SemanticAnnotations { | ||
required DOMString name; | ||
required ValueType type; | ||
any value; | ||
boolean configurable = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The latest TD draft (https://w3c.github.io/wot-thing-description/#property) supports observable and writable.
We need to check what will/should be the default value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
index.html
Outdated
DOMString name; | ||
dictionary ThingPropertyInit: SemanticAnnotations { | ||
required DOMString name; | ||
required ValueType type; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Align with TD draft (call it outputData
) ?
index.html
Outdated
Function action; | ||
dictionary ThingActionInit: SemanticAnnotations { | ||
required DOMString name; | ||
ValueType inputDataDescription; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Align with TD draft, name it inputData
and outputData
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
inputData
would imply this is data, but it is a description of input data.
index.html
Outdated
ThingDescription dataDescription; | ||
dictionary ThingEventInit: SemanticAnnotations { | ||
required DOMString name; | ||
ValueType dataDescription; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Align with TD draft, name it outputData
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
outputData
is a bad name, usually events have "data" in JS. This API is for developers.
index.html
Outdated
@@ -962,31 +837,46 @@ <h2>Examples</h2> | |||
<pre class="example highlight" title="Create a new blank exposed Thing"> | |||
WoT.createExposedThing(thingDescription) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Old API example. Should be WoT.produce
without Promise and then
etc
Also in addAction there is still old handler code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the catch. Done.
Signed-off-by: Zoltan Kis <[email protected]>
… discovery constraint matching. Signed-off-by: Zoltan Kis <[email protected]>
There is still a lot of work needed on SemanticAnnotations and DataSchema, but for the moment this is good to be merged. |
I get a ReSpec warning for undefined Observable, but it's defined. Someone please take another look and try to fix. |
Merging is fine by me also! Note: the ReSpec issue you are seeing relates to the observable attribute in "5.7.1 The ThingPropertyInit dictionary". The name collision seems to cause that issue. Renaming the attribute made the ReSpec issue disappear. Let's try to look into after merging... |
This is merged now. Thank you all for the comments and reviews. |
Don't merge yet, this is work in progress.
For the rendered version of the tip of the PR, use this link.
Signed-off-by: Zoltan Kis [email protected]