[ 4 posts ]

alexlebek

  • Joined: Fri Nov 13, 2009 1:47 am
  • Posts: 67
  • Offline
  • Profile

problem with event bubbling

Post Posted: Wed Feb 24, 2010 4:08 am
+0-
Hi,
I have some custom events bubbling between widgets in different modules (one YUI instance) but they only bubble if I add the following dummy bit of code into bindUI() of the firing widget:

this.on("mycustomevent", function(e) { Y.log("HERE I AM"); } );

I guess the custom event thinks no-one is listening for it and so this.fire("mycustomevent") doesn't broadcast.

I have listeners for the custom events in the event target modules but these only fire with the above dummy listener included in the module firing the event.
I have followed the custom event documentation closely but nevertheless must have misunderstood something. Any ideas?

Thanks

Alex

Adam Moore

YUI Contributor

  • Username: adam
  • Joined: Wed Sep 03, 2008 11:16 am
  • Posts: 356
  • GitHub: apm
  • Gists: apm
  • Offline
  • Profile

Re: problem with event bubbling

Post Posted: Wed Feb 24, 2010 10:38 am
+0-
Please linik a full example. Bubbling and broadcasting are different in YUI, which are you doing? What YUI dependencies been included on the page?

alexlebek

  • Joined: Fri Nov 13, 2009 1:47 am
  • Posts: 67
  • Offline
  • Profile

Re: problem with event bubbling

Post Posted: Thu Feb 25, 2010 1:18 am
+0-
Hi,
I am bubbling - as I understand it I should use 'broadcast' when the YUI instance or other YUI instances are the listeners. My app is within a local environment - I need to create a simplified test harness for this. I have included 'event', 'event-custom', 'event-custom-complex'.

Do you think the problem I have relates to the 'exit' case referred to in this comment in event-target.js for the 'fire' method :
*
* If the custom event object hasn't been created, then the event hasn't
* been published and it has no subscribers. For performance sake, we
* immediate exit in this case. This means the event won't bubble, so
* if the intention is that a bubble target be notified, the event must
* be published on this object first.

This comment(and code) suggests I do need to publish even if I am using the default configuration for custom events. This comment implies also that I must publish in the target object - not the firing object - but what if I have other targets?

Is there a way to dump the custom event queue with a list of listeners?
I will create test case and perhaps see where I am going wrong.

Thanks
Alex

alexlebek

  • Joined: Fri Nov 13, 2009 1:47 am
  • Posts: 67
  • Offline
  • Profile

Re: problem with event bubbling

Post Posted: Fri Feb 26, 2010 6:10 am
+0-
I have a small test case which demonstrates the problem I am having. I have obviously missed some basic thing.

The test is based on the yui3 custom event example and extends the eaxmple to include a new module (module1) with a custom widget which renders a slider.

The slider 'slideEnd' event causes the widget to fire a custom event to be received by the Publisher object.
The Publisher instance only receives this event if I explicitly *also* listen for the custom event in the widget that fired it.

The link is: http://yui.alexlebek.co.uk/event-ce.html

Any enlightening thoughts appreciated!

Alex
  [ 4 posts ]
Display posts from previous:  Sort by  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum