W3C home > Mailing lists > Public > www-dom@w3.org > July to September 2009

Re: [DOM3 Events] Initialising events (concerns)

From: Sergey Ilinsky <castonet@yahoo.co.uk>
Date: Thu, 24 Sep 2009 11:32:09 +0000 (GMT)
Message-ID: <338685.94694.qm@web24405.mail.ird.yahoo.com>
To: Doug Schepers <schepers@w3.org>
Cc: "www-dom@w3.org" <www-dom@w3.org>
Hi, Doug,

--- On Thu, 24/9/09, Doug Schepers <schepers@w3.org> wrote:

> Sergey Ilinsky wrote (on 9/24/09 6:36 AM):
> > 
> > I am talking about event initialization methods -
> changing
> > initXXXEvent to something different, such as possible
> properties bag
> > passing.
> 
> We aren't adding property-bag passing.  We're
> considering allowing attributes to be writable between the
> time the event is created and when it is dispatched. 
> We would keep the existing initialization methods, for
> back-compat (though we are weighing the costs and benefits
> of not adding new ones for the new interfaces).

CustomEvent should help. It allows to pass a bag of properties.

In the application one could implement a simple convenience function:

function dispatchCustomEvent(oTarget, sType, /* [ */ bCanBubble, bCancelable, oBag /* ] */) {
    var oEvent = oTarget.ownerDocument.createEvent("CustomEvent");
    oEvent.initEvent(sType, !!bCanBubble, !!bCancelable, oBag || null)
    oTarget.dispatchEvent(oEvent);
}

dispatchCustomEvent(document.querySelector("#id"), "event");

or a method:

Element.prototype.dispatchCustomEvent(sType, /* [ */ bCanBubble, bCancelable, oBag /* ] */) {
    var oEvent = this.ownerDocument.createEvent("CustomEvent");
    oEvent.initEvent(sType, !!bCanBubble, !!bCancelable, oBag || null)
    this.dispatchEvent(oEvent);
}

var o = {my:"my"};
document.querySelector("#id").dispatchCustomEvent("test", true, false, o);

Again, I believe, there are almost no use cases for any events dispatching into DOM apart for unit testing, so maybe an implementation of convenience methods in a certain application framework would suffice.

> 
> A language for which this is a problem would not have to
> allow the attributes to be writable.  It could continue
> to use the initialization methods.
> 
> Is this a problem for Java?

Unfortunately I do not know, got no experience with Java.

Regards,
Sergey/



      
Received on Thursday, 24 September 2009 11:32:51 GMT

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