Not quite getting events

edited May 2014 in Newbie Questions
Hi! I'm not quite getting Enyo events yet. I figure I'm just looking at things wrong, but despite a lot of poking I haven't been able to figure it out yet. As a way to Learn Enyo, I'm trying to build a simple to-do app. I took some existing template and stripped it down, and am building it up from there.

The code in question is here:

https://gist.github.com/wpietri/8256b601a0e91d2922fc

And what's puzzling me what happens when I edit the text of a to-do item. At line 36, I ask for an itemChanged function to be called on input events. I was expecting it to call the function at line 37 ("itemChanged1), or maybe at line 44 ("itemChanged2"). But instead it's calling the one at line 68 ("itemChanged3").

Stepping through the code in Component.js, I'm having a hard time following the logic. In particular, in dispatchEvent it checks to see if there's a delegate, and in this case there is one containing the function on line 37. But that method never gets called.

Is that how it should be working?

Comments

  • I think this is either a bug resulting from an unexpected use case.

    tl;dr
    Wrapping the Repeater with another control will work around the issue.

    http://jsfiddle.net/ryanjduffy/Xn8aR/

    Normally, events are handled by the owner of the firing control. With Repeater, the item is actually owned by an intermediate control (enyo.OwnerProxy) rather than the kind that declared it (ToDoList in your example). OwnerProxy tries to fix the delegation chain but updating the delegate of events that pass through it to its owner (the Repeater). It's making an assumption that the Repeater will be owned by the control that will handle the event. In your case, the Repeater is what you (and I) expect to handle the event but it's being leap-frogged.

    I'm not sure what the fix for this would be but a workaround is to wrap the Repeater as in the above fiddle.

  • Ok! I'll give that a try. Thanks, Ryan!

    This being an unexpected use case makes me think that there's a different style I should be working in. Is there a different way folks here would approach creating a UI like that and then handling events from it?
Sign In or Register to comment.