Last active
December 14, 2015 16:49
-
-
Save lsmith/5117861 to your computer and use it in GitHub Desktop.
Getting an idea of what the expectation of behavior between on() and after() phase of a stopped event is.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var child = new Y.EventTarget({ emitFacade: true }), | |
| parent = new Y.EventTarget({ emitFacade: true }), | |
| grandparent = new Y.EventTarget({ emitFacade: true }); | |
| child.addTarget(parent); | |
| parent.addTarget(grandparent); | |
| child.publish('foo', { | |
| defaultFn: function () { console.log("default function"); } | |
| }); | |
| child.on('foo', function (e) { console.log('child.on()'); }); | |
| parent.on('foo', function (e) { | |
| console.log('parent.on()'); | |
| e.stopPropagation(); | |
| }); | |
| grandparent.on('foo', function (e) { console.log('grandparent.on()'); }); | |
| child.after('foo', function (e) { console.log('child.after()'); }); | |
| parent.after('foo', function (e) { console.log('parent.after()'); }); | |
| grandparent.after('foo', function (e) { console.log('grandparent.after()'); }); | |
| child.fire('foo'); | |
| // What do you think should be logged? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Okay, with the defaultFn, things don't change too much. Again, my expectation and my ideal behaviours differ:
I'd expect this to happen:
child.on()
parent.on()
default function
child.after()
But contrary to what others have said, I would want this to happen:
child.on()
default function
child.after()
parent.on()
parent.after()
To me it seems more logical that the after() of a child should precede the on() of a parent, and also it seems more convenient to fire the after() event even if propagation has stopped.