[jsb] dispatchEvent

14 views
Skip to first unread message

Marijn

unread,
Nov 13, 2010, 1:49:55 PM11/13/10
to base2-js
Hi everybody,

I was just wondering if it is possible to detect if an event listener
called prevent default for custom events. If so how can I gain access
to it?

I've tried passing an object along with the dispatchEvent method but
it doesn't seem to hold any reference to isDefaultPrevented.

Kindest regards,

Marijn

Dean Edwards

unread,
Nov 17, 2010, 3:21:01 PM11/17/10
to base...@googlegroups.com

No, I haven't added a method like that. I'm should do something though.

I was thinking of adding a defaultAction property to the custom event.
This property would be a callback function that gets called once the
event bubbling is complete.

What do you think of this idea?

BTW, if you ask this question then you are probably using JSB quite a
lot. I've made a few changes to it that you may be interested in. Let me
know if you want to test-drive the latest code. I'm thinking that it is
about time I checked in my latest work anyway. :)

-dean

Marijn

unread,
Nov 18, 2010, 10:20:43 AM11/18/10
to base2-js


On Nov 17, 9:21 pm, Dean Edwards <dean.edwa...@gmail.com> wrote:
> On 13/11/2010 18:49, Marijn wrote:
>
> > Hi everybody,
>
> > I was just wondering if it is possible to detect if an event listener
> > called prevent default for custom events. If so how can I gain access
> > to it?
>
> > I've tried passing an object along with the dispatchEvent method but
> > it doesn't seem to hold any reference to isDefaultPrevented.
>
> No, I haven't added a method like that. I'm should do something though.
>
> I was thinking of adding a defaultAction property to the custom event.
> This property would be a callback function that gets called once the
> event bubbling is complete.

I've made a small example of what my original intention was.
I think I prefer that in favor of passing a callback. It feels more
transparent to me.

https://gist.github.com/705105

> What do you think of this idea?
>
> BTW, if you ask this question then you are probably using JSB quite a
> lot. I've made a few changes to it that you may be interested in. Let me
> know if you want to test-drive the latest code. I'm thinking that it is
> about time I checked in my latest work anyway. :)

I will, I'll send you a personal message with an example of some of my
latest work with it.

I'll definitely want to testdrive:-)

By the way, have you considered moving to github?

I think I remember you _hate_ scm's but I really can recommend git.
It's really transparent, easy to use tool especially for a project
like base2.

> -dean

Kindest regards,

Marijn

Dean Edwards

unread,
Nov 18, 2010, 12:26:40 PM11/18/10
to base...@googlegroups.com, Marijn
On 18/11/2010 15:20, Marijn wrote:
>> I was thinking of adding a defaultAction property to the custom event.
>> This property would be a callback function that gets called once the
>> event bubbling is complete.
>
> I've made a small example of what my original intention was.
> I think I prefer that in favor of passing a callback. It feels more
> transparent to me.
>
> https://gist.github.com/705105

Mmm. Let me think about it. There is no analogous call in the DOM API.
I'm still inclined to think that an event has a default action that can
be prevented. The action should be tied to the event somehow. It's not
for event listeners to decide what the default action should be. It is
for the event dispatcher to decide.

>> BTW, if you ask this question then you are probably using JSB quite a
>> lot. I've made a few changes to it that you may be interested in. Let me
>> know if you want to test-drive the latest code. I'm thinking that it is
>> about time I checked in my latest work anyway. :)
>
> I will, I'll send you a personal message with an example of some of my
> latest work with it.
>
> I'll definitely want to testdrive:-)

OK. I'll warn you that base2 version 2.0 is a little bit different to
version 1.0. You probably won't notice a lot of the changes. The main
change is the way that Packages are created.

In the base2 core, I've removed the JavaScript package and the Map class
(Collection does everything that Map does). I'm also renaming Module to
Trait (not final), to avoid people confusing it with the module pattern.
I'm also providing base2.exec, base2.require and base2.ready which can
be used to execute base2 code.

base2.DOM is renamed to base2.dom but other than that is largely the same.

base2.JSB is renamed to base2.jsb. All base2 packages names are now
lowercase. The JSB API has changed slightly:

addClass --> classList.add
removeClass --> classList.remove
hasClass --> classList.contains
toggleClass --> classList.toggle
setStyle --> style.set
getStyle --> style.get

I've also added a behavior method called "fire" which is optimised for
dispatching custom events. It is also a lot less verbose than
dispatchEvent (which is still supported).

I'll also be supporting two new packages: base2.io and base2.jst
(templating). There will also be base2.XMLHttpRequest which is compliant
with the Selectors API 2 spec and fixes lots of cross-browser bugs.

So, there are quite a lot of differences but they are mostly
boiler-plate. Like I said the APIs are mostly the same but with
improvements in speed and accuracy (for DOM APIs).

> By the way, have you considered moving to github?

I've thought about it. I like a lot of things about googlecode, it's
reliability and issue tracking particularly. I've already moved from
SourceForge to googlecode. I'm not sure I can be bothered to move again.

-dean

Reply all
Reply to author
Forward
0 new messages