0

Why isn't my event fired in foo bubbling up to bar?

var foo = Y.one(".foo"),
    bar = Y.one(".bar");

foo.addTarget(bar);

foo.on("myEvent", function () {
    //this log statement executes
    Y.log("In foo listener");
});

bar.on("myEvent", function () {
    //this log statement doesn't execute.
    //I don't understand why.  I think it
    //should because I expect myEvent to 
    //bubble from foo to bar since I used
    //addTarget
    Y.log("In bar listener");
});

foo.fire("myEvent");

JS Fiddle: http://jsfiddle.net/steaks/tJnLf/

Charles
  • 50,943
  • 13
  • 104
  • 142
Steven Wexler
  • 16,589
  • 8
  • 53
  • 80

1 Answers1

2

You have to publish myEvent from foo and set emitFacade to true. http://yuilibrary.com/yui/docs/event-custom/#facade

http://jsfiddle.net/tJnLf/27/

YUI().use('event-custom', 'node', function(Y) {
    Y.on('domready',function(e) {   
        var foo = Y.one(".foo"),
            bar = Y.one(".bar");

        foo.publish("myEvent", {
            emitFacade: true
        });

        foo.addTarget(bar);

        foo.on("myEvent", function () {
            Y.log("In foo listener");
        });

        bar.on("myEvent", function () {
            Y.log("In bar listener");
        });

        foo.fire("myEvent");
    });
});
Trevor Dixon
  • 23,216
  • 12
  • 72
  • 109