Skip to content
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

Add a constructor to both the WebIDL and TypeScript definitions of the ExposedThing interface #516

Closed
danielpeintner opened this issue Oct 24, 2023 · 4 comments · Fixed by #517

Comments

@danielpeintner
Copy link
Contributor

In this context, I noticed that we might want to also add a constructor to both the WebIDL and TypeScript definitions of the ExposedThing interface.

see #515

@zolkis
Copy link
Contributor

zolkis commented Oct 24, 2023

But we agreed earlier that ExposedThing objects can only be created from the factory methods. We have steps for constructing ExposedThing, used from the steps for the factory method produce(), but those cannot be used in a JS constructor.
We can add bare-object JS constructors, but then we need to spec it accordingly, just creating the bare JS objects, but then we need a 2nd stage init (involving all async operations) like expanding the init dict to a TD. I think this might get confusing. It's cleaner to have a factory method.

For ConsumedThing it was a bit different, since the constructor only copied the init dict as TD internal slot, then all async ops were done in the methods. If we want to align, we can remove the constructor here, and use the pattern we follow with ExposedThing.

@JKRhb
Copy link
Member

JKRhb commented Oct 28, 2023

Removing the constructor from ConsumedThing to align it with the ExposedThing interface sounds reasonable to me. I assume the sections about constructing ConsumedThing and ExposedThing (e.g., https://w3c.github.io/wot-scripting-api/#constructing-exposedthing) should be kept even though the constructors are not exposed via the interfaces, right? Or should these sections also be removed?

@zolkis
Copy link
Contributor

zolkis commented Oct 28, 2023

The steps for constructing, well, for producing (since they are created by a factory method) will remain in the spec, and they belong to the consume() and produce() steps. But if the order of introducing concepts makes it more readable, we can factor out the construction steps and describe them later. I am thinking to rename these from "Constructing" to "Create" in order to avoid possible confusion with constructors.

@danielpeintner
Copy link
Contributor Author

Call Nov 07

  • We don't uses constructors (neither in WebIDL nor in TS)
  • constructor are sync operations. Factories can be used instead for async operations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants