W3C home > Mailing lists > Public > whatwg@whatwg.org > November 2009

[whatwg] createEvent() in Web Workers?

From: Simon Pieters <simonp@opera.com>
Date: Fri, 27 Nov 2009 17:02:00 +0100
Message-ID: <op.u319hmtxidj3kv@zcorpandell.linkoping.osa>
On Fri, 27 Nov 2009 16:50:21 +0100, Jonathan Cook  
<jonathan.j5.cook at gmail.com> wrote:

> Simon Pieters wrote:
>> There's ErrorEvent.initErrorEvent, and dispatchEvent is exposed in  
>> workers, but there's no createEvent (because there's no document). Are  
>> there use cases for sending events in a worker? Should we expose  
>> createEvent somewhere? Should we remove initErrorEvent?

> I would like to see createEvent in WebWorker.  My (theoretical) use case
> would involve using custom eventing to load or set new message
> handlers.  Flow would be something like this
> window A creates worker 1
> window A sends message to worker 1
> worker 1 sends message to window A
> window A sends message to worker 1
> worker 1 creates an event "switch" in response to message, passing the
> message in the event: createEvent("switch",message)
> worker 1 switch event handler loads / sets new message handler, mutating
> itself into worker 1 sub 1 and calls the new message handler on the
> passed message
> worker 1 sub 1 sends message to window A
> Anyone think this theoretical use case or some derivative is a useful
> abstraction to aid in code organization and flow control?  I would think
> since an eventing queue is specified for message handling that adding
> custom events would not be much additional effort for implementers.
> initErrorEvent would seem to put the DOM Events Level 3 createEvent and
> initEvent methods together.  Is there a reason that this approach was
> chosen instead of mirroring DOM Events?  The simple answer seems to be
> because there is no DOM :)

An idea for creating events is to support [Constructor] on all event IDLs,  
which makes the createEvent method unnecessary.

Maybe we could even make the arguments to the constructor be called to  
initFooEvent() directly, so instead of doing

    var e = document.createEvent('MouseEvents');
    e.initMouseEvent('click', ...);

you could do

    foo.dispatchEvent(new MouseEvent('click', ...))

I've cc-ed www-dom since this is a suggestion for a change to DOM Events.

Simon Pieters
Opera Software
Received on Friday, 27 November 2009 08:02:00 UTC

This archive was generated by hypermail 2.4.0 : Wednesday, 22 January 2020 16:59:19 UTC