[ 4 posts ]

Wei Wang

YUI Contributor

  • Username: Shinwei
  • Joined: Wed Oct 27, 2010 1:45 pm
  • Posts: 91
  • GitHub: onlywei
  • Gists: onlywei
  • Offline
  • Profile

Is there any way to make sure an event is fired from self?

Post Posted: Tue Jul 31, 2012 11:21 am
+0-
If I have an EventTarget that happens to have children who use the same event prefix, is there an easy way to make sure that the events I'm subscribing to are fired from the 'self' target and not a child?

Daniel Ji

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

Re: Is there any way to make sure an event is fired from sel

Post Posted: Tue Jul 31, 2012 12:57 pm
+0-
http://yuilibrary.com/yui/docs/base/

Usually if your class extends Y.Base, then the name of the class is prefixed to the event you are firing. I use Y.Views (which extend from Y.Base) and when I do something like...
Code:
myView.fire('myEvent')

Then, the event name gets prepended with the name of the view class. So the 'myEvent' would actually be 'myView:myEvent' when I inspect the event facade for the event type. So you can discriminate based on the prefix.

Note, that you need to fire the event from a class that extends from Base for this work as described, which after reading your original post does not apply to you, since you're just using EventTarget directly :)

Or actually, even easier yet, either the currentTarget or target of the event facade (i forget which one it is) should always be the 'self' class you're referring to. So you can just check if the currentTarget or target is the 'self'.

Daniel Ji

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

Re: Is there any way to make sure an event is fired from sel

Post Posted: Tue Jul 31, 2012 1:00 pm
+0-
Yep, it seems like e.target is what you want.

http://yuilibrary.com/yui/docs/event/#basics

Wei Wang

YUI Contributor

  • Username: Shinwei
  • Joined: Wed Oct 27, 2010 1:45 pm
  • Posts: 91
  • GitHub: onlywei
  • Gists: onlywei
  • Offline
  • Profile
Tags:

Re: Is there any way to make sure an event is fired from sel

Post Posted: Tue Jul 31, 2012 3:12 pm
+0-
Thanks guys. Wow I can't believe I didn't think of that one. You guys rock!
  [ 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