I find logic here very confusing I'd rather prefer flow like:

```js
var readyEvents = filter(events, isReadyEvent)
var pageEvents = map(events, function({target, type}) { type: type, target: target, page: pageFor(target) })
var pageReadyEvents = filter(events, function({page, type}) page.contentScriptWhen === readyEventMap[type])
on(pageReadyEvents, "data", function({page, type}) {
  attach(page, workerFor(page))
  emit(page, 'ready', ...)
})
```