Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Capture the hasListener consensus #225

Closed
slightlyoff opened this issue Apr 8, 2014 · 7 comments
Closed

Capture the hasListener consensus #225

slightlyoff opened this issue Apr 8, 2014 · 7 comments

Comments

@slightlyoff
Copy link
Contributor

As per today's f2f discussion at Mozilla, we've decided on filtering event dispatch for the life of an active handler based on the list of event handlers which are registered in the SW global.

E.g., a SW without an onfetch handler will never ever be sent a fetch event:

// because oninstall is registered synchronously, it will be dispatched
self.oninstall = function(e) {
  // no fetch events will ever be sent to this SW
  self.onfetch = function(e) { ... };
};
// this SW will also be sent sync events
self.onsync = function(e) { ... };

The exact spec language will need to look at the list of registered handlers as the very first microtask-end task during the initial evaluation of the SW script. Subsequent boot-ups of the SW will only be triggered by the list of events captured as a result of that first eval. Updates (new oninstall chances) are the only time the list of event handlers will be re-litigated. E.g., the list of events you register for is fixed per-version by the events you register at the top-level the very first time.

@tabatkins
Copy link
Member

Can you just say "when a listener is registered for an X event, record that the SW is listening to X events", and only update that record during install/update callbacks?

@jakearchibald
Copy link
Contributor

@tabatkins That involves wrapping addEventListener in something that does the recording. I'm fine with that, but others not-so.

@annevk
Copy link
Member

annevk commented Apr 9, 2014

Not everyone is happy about doing this: http://krijnhoetmer.nl/irc-logs/whatwg/20140409#l-34

It seems @Hixie and @tabatkins are talking a little bit past each other there. I'm pretty sure @Hixie is only ok with overloading onfetch, not with addEventListener. (The latter would require an explicit API call for opting in.)

@slightlyoff
Copy link
Contributor Author

I'd also like to avoid overriding addEventListener. It's possible to vend an ES6 proxy for the global and observe calls, but it seems simpler to retreat into bookkeeping magic and note that events with listeners added at the end of evaluation will be captured in the record. We don't need to enumerate how this happens right now except to say that there is an internal record and we do reference it.

@KenjiBaheux
Copy link
Collaborator

@slightlyoff @jakearchibald this needs-spec issue hasn't been updated in a while and a quick read of the spec didn't reveal anything relevant. Is this issue still current?

@annevk
Copy link
Member

annevk commented Sep 5, 2014

#445 has a different approach to this.

@KenjiBaheux
Copy link
Collaborator

Thanks, let's see how the discussion spans out on #445

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants