YUILibrary - Open source JavaScript and CSS for building richly interactive software.
Fork YUI on GitHub
  [ 2 posts ]

Joh

  • Username: snilsor
  • Joined: Fri Jul 10, 2009 2:22 am
  • Posts: 14
  • Offline
  • Profile

Y.Global CustomEvent remains in .stopped=2 state if fired 2x

Post Posted: Wed Nov 25, 2009 3:10 am
+0-
In brief: A second fire on a CustomEvent only triggers the first subscriber. All others are only called on first fire.
~~~~~~~~~~~~~~~~~~~~
I have an link that fires with Y.on('click') an Y.Global.fire('form:submit'); CustomEvent

Other parts of my code set several subscribers, e.g.
a.) Y.Global.on('form:submit', functionA);
b.) Y.Global.on('form:submit', functionB);

functionA and functionB check if they are responsible and prevent propagation by returning false - or let others handle the event:

Code:
functionA = function(e)
{ ...
    if (iAmResponsible)
    {
        (do something)
   return false; // stop propagation to subscriber functionB
    }
}

~~~~~~~~~~~~~~~~~~~~~

The problem:
If the event ist first fired, everything is fine. functionA is called, it ignores the call (is not responsible check) and functionB gets the call and works with it and returns false to stop propagation.
If the same event is then later again fired (same code), only functionA is called, it again ignores the call, but functionB never sees this and any further events.

Reason:

On the second fire, the CustomEvent instance still has both subscribers correctly (I checked this), but it has a property this.stopped = 2 still set. That is the difference to the first fire. It results in event-custom-debug.js L809 to stop the iteration over all subscribers, because on the first fire of event it was set in L807 due to the returnvalue FALSE of my functionB handling the event and preventing further propagation.

Question:
Do I need to "reset" CustomEvents status myself ? I thought they are stateless after all subscribers have been called?

I expect this to be a bug or I misunderstood the concept of CustomEvents.
Thank you in advance for your help.

Luke Smith

YUI Developer

  • Username: lsmith
  • Joined: Thu Aug 28, 2008 7:50 am
  • Posts: 149
  • Location: Sunnyvale
  • GitHub: lsmith
  • Gists: lsmith
  • IRC: ls_n
  • YUI Developer
  • Offline
  • Profile
Tags:

Re: Y.Global CustomEvent remains in .stopped=2 state if fired 2x

Post Posted: Wed Nov 25, 2009 10:21 am
+0-
It's a bug. Please file it.

A couple things to note about the code structure you've touched on:
1) use e.stopPropagation()
2) The use of multiple YUI instances is typically not the best way to use YUI 3. It is recommended that custom modules be created to encapsulate custom logic and then use(..)d from a single YUI instance, using the callback to glue the module pieces together as is necessary for the given page. Caridy and Eric F gave nice talks about this at YUIConf (vids available on YUI Theater). If you need help or have any questions wrt setting up an architecture like this, we'd be glad to assist either here or in the #yui channel on IRC (freenode.org)

Thanks for doing the discovery on this and I appreciate the caution before assuming a finding is a bug :)
  [ 2 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