[w3c/ServiceWorker] Allow users to extend ExtendableEvent, anywhere (#1290)

Hello.

As a JavaScript developer, I have, for my own use & without realizing it, [recreated something very akin to the ExtendableEvent interface](https://github.com/rektide/async-event-target/blob/master/async-event-target.js): an event that listeners can delay termination on, an event that has a lifetime that resolves. This is a pretty abstract concept, and it's one that I think that ExtendableEvent was created to fulfill for a specific use case that it ought to be made to provide instead for users of the web platform, and ServiceWorker already has a viable interface that I feel should be hoisted out of ServiceWorker. Just as EventTarget was made capable of being extended in JavaScript, I would like to see ExtendableEvent be made into a class that other classes can extend off of.

Notably missing from the current interface is any way to signal the completion of the lifetime extending `waitUntil()` promises. I'm not sure how flexible an [Foo]Event constructor can be, but perhaps something akin to [how Fetch constructor was made to accept an [Abort]Controller](https://github.com/whatwg/fetch/pull/523) could be used to signal. However, it seems odd to signal completion of an event by firing another event, so I'm less than fully committed to trying to follow that mold exactly.

In my own async-event-target library (linked above) I was focusing more on the bigger scope, of an EventTarget that exhibits dispatch resolution across a lifetime, rather than focusing just on the event. To that effect, I made `dispatchEvent()` be able to return a promise that signalled completion. Given that the promise is a truthy value, seemed like a passable path forward, but it's definitely optional for this work. I think it would make sense to bring in ExtendableEvent alone, but it may be more useful and make more sense if EventTarget is itself also extended.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/w3c/ServiceWorker/issues/1290

Received on Monday, 19 March 2018 15:32:03 UTC