W3C home > Mailing lists > Public > www-dom@w3.org > October to December 2009

Re: [whatwg] createEvent() in Web Workers?

From: Simon Pieters <simonp@opera.com>
Date: Fri, 27 Nov 2009 17:02:00 +0100
To: "Jonathan Cook" <jonathan.j5.cook@gmail.com>, WHATWG <whatwg@whatwg.org>
Cc: "www-dom@w3.org" <www-dom@w3.org>
Message-ID: <op.u319hmtxidj3kv@zcorpandell.linkoping.osa>
On Fri, 27 Nov 2009 16:50:21 +0100, Jonathan Cook  
<jonathan.j5.cook@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', ...);
    foo.dispatchEvent(e);

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 16:02:36 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Friday, 22 June 2012 06:14:04 GMT