Skip to content

Remove eventHandler #423

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

Merged
merged 11 commits into from
Sep 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 9 additions & 82 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2397,8 +2397,6 @@ <h2>The <dfn>ExposedThing</dfn> interface</h2>
EventSubscriptionHandler handler);
ExposedThing setEventUnsubscribeHandler(DOMString name,
EventSubscriptionHandler handler);
ExposedThing setEventHandler(DOMString name,
EventListenerHandler eventHandler);
Promise&lt;undefined&gt; emitEvent(DOMString name,
InteractionInput data);

Expand All @@ -2422,7 +2420,6 @@ <h2>The <dfn>ExposedThing</dfn> interface</h2>
callback EventSubscriptionHandler = Promise&lt;undefined&gt;(
optional InteractionOptions options = null);

callback EventListenerHandler = Promise&lt;InteractionInput&gt;();
</pre>

<section data-dfn-for="ExposedThing">
Expand Down Expand Up @@ -3124,21 +3121,6 @@ <h3>The <dfn>ActionHandler</dfn> callback</h3>
</div>
</section>

<section data-dfn-for="EventListenerHandler">
<h3>The <dfn>EventListenerHandler</dfn> callback</h3>
<p>
A function that is called when an associated <a>Event</a> is triggered
and provides the data to be sent with the <a>Event</a> to subscribers.
Returns a {{Promise}} that resolves with {{InteractionInput}} value
that represents the <a>Event</a> data, or rejects with an error.
</p>
<p class="note">
Applications MAY return {{ReadableStream}} from an {{EventListenerHandler}}
Implementations will then use the stream provided in
{{InteractionOutput}} when constructing the event notification.
</p>
</section>

<section data-dfn-for="EventSubscriptionHandler">
<h3>The <dfn>EventSubscriptionHandler</dfn> callback</h3>
<p>
Expand Down Expand Up @@ -3321,75 +3303,17 @@ <h3>The <dfn>EventSubscriptionHandler</dfn> callback</h3>
</div>
</section>

<section> <h3>The <dfn>setEventHandler()</dfn> method</h3>
<p>
Takes as arguments |name:string| and |eventHandler:EventListenerHandler|.
Sets the event handler function for the specified <a>Event</a>
matched by |name|.
Throws on error.
Returns a reference to |this| object for supporting chaining.
</p>
<p>
The |eventHandler| callback function will implement what to do when the
event is emitted. It SHOULD resolve with a value that represents the
<a>Event</a> data, or reject with an error.
</p>
<p>
There MUST be at most one handler for any given <a>Event</a>, so newly added handlers MUST replace the previous handlers.
</p>
<div>
When the method is invoked with |name:string| and
|eventHandler:EventListenerHandler|, run the following steps:
<ol>
<li>
If invoking this method is not allowed for the current scripting context for security reasons, [= exception/throw =] a {{SecurityError}} and abort these steps.
</li>
<li>
Let |interaction| be the value of [[\td]]'s |events|'s
|name|.
</li>
<li>
If an <a>Event</a> with the name |name| is not found,
[= exception/throw =] a {{NotFoundError}} and abort these steps.
</li>
<li>
Set the <a>internal slot</a> [[\eventHandler]] of |interaction| to
|eventHandler|.
</li>
<li>
Return `this`.
</li>
</ol>
</div>
</section>

<section> <h3>Handling <a>Events</a></h3>
<div>
When an <a>Event</a> with name |name| is emitted with
|data:InteractionInput| either by the underlying platform or by the
|data:InteractionInput| by the
<a href="#the-emitevent-method">emitEvent()</a> method, run the
following steps:
<ol>
<li>
Let |interaction| be the value of [[\td]]'s |events|'s
|name|.
</li>
<li>
If |data| is not defined or `null`,
<ol>
<li>
Let |eventHandler| be the value of the [[\eventHandler]]
<a>internal slot</a> of |interaction|.
</li>
<li>
If |eventHandler| is failure, abort these steps.
</li>
<li>
Let |data| be the result of awaiting to resolve the invocation
of |eventHandler|. If it rejects, abort these steps.
</li>
</ol>
</li>
<li>
For each |subscriber| in the <a>internal listener list</a> of
|interaction|, run the following sub-steps:
Expand All @@ -3398,6 +3322,12 @@ <h3>The <dfn>EventSubscriptionHandler</dfn> callback</h3>
Create an <a>Event</a> notification |response| according to the
<a>Protocol Bindings</a> from |data| and |subscriber|, including
its |options|.
</li>
<li>
If |data| is `undefined`, assume that the notification |response|
will contain an <emph>empty</emph> data payload as specified by <a>Protocol Bindings</a>.
</li>
<li>
If the underlying protocol stack permits conveying event errors and
if an error condition has been detected by the UA, create |response|
as an error notification according to the <a>Protocol Bindings</a>,
Expand Down Expand Up @@ -3439,11 +3369,8 @@ <h3>The <dfn>EventSubscriptionHandler</dfn> callback</h3>
</li>
<li>
Make a request to the underlying platform to emit an <a>Event</a>
with |data|.
<p class="note">
This will trigger the <a href="#handling-events">handling events</a>
steps.
</p>
with |data|. Call the <a href="#handling-events">handling events</a>
steps.
</li>
</ol>
</div>
Expand Down
10 changes: 0 additions & 10 deletions typescript/scripting-api/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,14 +276,6 @@ declare namespace WoT {
*/
setEventUnsubscribeHandler(name: string, handler: EventSubscriptionHandler): ExposedThing;

/**
* Takes as arguments name and eventHandler.
* Sets the event handler function for the specified Event matched by name.
* Throws on error.
* Returns a reference to the same object for supporting chaining.
*/
setEventHandler(name: string, handler: EventListenerHandler): ExposedThing;

/**
* Takes as arguments name denoting an Event name and data.
* Triggers emitting the Event with the given data.
Expand All @@ -304,8 +296,6 @@ declare namespace WoT {

export type EventSubscriptionHandler = (options?: InteractionOptions) => Promise<void>;

export type EventListenerHandler = () => Promise<InteractionInput>;

}

declare module "wot-typescript-definitions" {
Expand Down