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

@jakearchibald I like the second proposal of using a condition object compared to list of constructors. I suggest creating RouterCondition class and a RouterPredicate class to help better express the conditions. RouterCondition class instantiates a self contained condition object that is passed to router.add function. It also exposes a test method that can be used to validate whether a request satisfies the condition. RouterPredicate class can list all the predicates that are allowed on a particular route.

```javascript
const condition = new RouterCondition((route /* of type RouterPredicate */) => {
  return route.method('GET') &&
         route.urlStartsWith('/avatar') && 
         !route.urlEndsWith('.mp4');
// return !route.method('POST');
});

router.add(condition, sources);
condition.test(request); // returns boolean; useful for other purposes
```

What do you think?

-- 
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-452371314

Received on Tuesday, 8 January 2019 16:54:25 UTC