[ 3 posts ]

Daniel Ji

  • Username: humblepie
  • Joined: Tue Feb 28, 2012 10:30 am
  • Posts: 147
  • GitHub: humblepie
  • Gists: humblepie
  • Offline
  • Profile
Tags:

Setting up an EventTarget bubble chain

Post Posted: Mon Aug 20, 2012 2:42 pm
+0-
So I got a simple example of chaining two views together so that when an event is fired from the 'subview', then the 'parentview' can respond with an alert.

However, I noticed that I need to publish each event, indicating that emitFacade = true.

Is there a way to say that all the events broadcasted from my Y.View instance will always emitFacades? Or do I need to specifically publish and fire each custom event that I want to bubble up?

http://yuilibrary.com/yui/docs/event-custom/#bubbling
I noticed from the article above that theres a way to enhance a class with EventTarget with emitFacade = true, but the Y.View already extends EventTarget I believe. So I don't think I can use what it does in the example...

Thanks.

http://jsbin.com/aqogam/1/edit

Steven Olmsted

YUI Contributor

  • Username: solmsted
  • Joined: Wed Apr 14, 2010 1:47 pm
  • Posts: 82
  • Location: Richmond, VA
  • GitHub: solmsted
  • Gists: solmsted
  • IRC: solmsted
  • Offline
  • Profile

Re: Setting up an EventTarget bubble chain

Post Posted: Mon Aug 20, 2012 7:15 pm
+0-
Hello. I must admit that the documentation regarding Y.EventTarget and emitFacade once confused me as well. I think I can help straighten this out.

The confusion comes from the publish method on Y.EventTarget. It accepts an option called emitFacade which defaults to false. There is an instance level parameter to change emitFacade to default to true. When Y.Attribute mixes itself with Y.EventTarget it configures emitFacade to default to true. Therefore Y.Base and anything else that extends Y.Attribute automatically defaults emitFacade to true.

Another cool thing about EventTarget, if you fire an event without publishing it, it will get published for you. If you rely on automatic publishing, I think the event always gets published with default parameters. If your object extends Y.Base, you're in luck because emitFacade defaults to true.

Here's another example of using nested views and custom event bubbling: http://jsfiddle.net/3HTzA/

I like to publish events within the initializer method just because it gives me a handy place to keep track of all my events, but notice that you can comment out the publish and the event bubbling still works.

Daniel Ji

  • Username: humblepie
  • Joined: Tue Feb 28, 2012 10:30 am
  • Posts: 147
  • GitHub: humblepie
  • Gists: humblepie
  • Offline
  • Profile

Re: Setting up an EventTarget bubble chain

Post Posted: Wed Aug 22, 2012 10:13 am
+0-
Hi Steven!

You are correct! In my sample code, I tried commenting out the event publishing and the events still bubbled as desired, since the subview and parentviews extended from Y.View, which extends Y.Base. That's good to know.

I 'fiddled' with your sample code and it works as you describe as well. Thanks for the response :)
  [ 3 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