Re: [w3c/ServiceWorker] Declarative routing (#1373)

> [...] why have a method that returns an instance + an illegal constructor, when a valid constructor can do the same job[...]

Well it's not entirely without precedent in Web APIs, `BaseAudioContext.createBuffer` for example ( although AudioBuffer is a valid ctor as well ). You are probably right about just using valid constructors though, I think the difference basically comes down to my preference in namespacing methods/classes.

> > Can anyone think of any methods that Conditions or Sources would actually need?
> 
> Yep, I documented some above. See "Are instances useful?".

Missed that, going to be honest I only scanned that post over my morning red bull. I guess condition instances could also be used for routing in the fetch handler.

```javascript
const markdownCondition = new RouterIfURLEnds('.md');

addEventListener("fetch", event => {
  if (markdownCondition .test(event)) {
    event.respondWith(renderMarkdown(event));
  }
});
```

Not a great example use case for serviceworkers, but a plausible one.

-- 
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/1373#issuecomment-452297766

Received on Tuesday, 8 January 2019 13:28:07 UTC