Re: [ServiceWorker] ServiceWorkerClient to Client (#588)

Out of curiosity, why are we allowing creation of window clients but not worker ones?

Why are we trying to squash windows and workers into a single class? visibilityState, focused, frameType, and focus() all seem inapplicable to workers. Seems better to move the rest of the properties to a base class and have a WindowClient, or similar.

---

Real Talk about constructors:

In general with constructors, all I want you to do is outline a clear story for how the objects the author sees came into being. If that can be "the browser called `new Client(...)` just like an author would", that's the best story. If it's "the browser called `new Client(..., secretToken, secretOptions)`", that's less satisfying, but sometimes necessary. In other words, how does `getAll()` actually work: if you say that it's impossible to construct `Client` instances that represent workers, then how did the browser do it? (Using a secret token/set of options, presumably. Why is only the browser allowed to do this? See below.)

I don't like the idea of `new Client(...)` causing side effects like opening a window. In general object construction should not have any real side effects IMO. For example that would mean that if calling `getAll()` returns a promise for 5 windows, you'd expect the browser to open 5 new windows before fulfilling the promise, since it had to create the objects before it could return them.

It seems more likely you want a design where `Client`'s constructor is of the form `new Client(informationGivingAPointerToImplementationWindowOrWorkerRepresentation)`. Since authors would never be able to create a well-formed pointer of this type, `new Client` will always throw for them. (So, in WebIDL terms, "there is no constructor".) Then when `getAll()` is called the implementation internally does `new Client(pointerData)` 5 times before fulfilling.

---
Reply to this email directly or view it on GitHub:
https://github.com/slightlyoff/ServiceWorker/issues/588#issuecomment-66830105

Received on Friday, 12 December 2014 20:27:53 UTC