can.Observe.delegate sets wrong event.currentTarget #123

Closed
rjgotten opened this Issue Oct 23, 2012 · 0 comments

Comments

Projects
None yet
2 participants
@rjgotten

Events returned to handlers bound through can.Observe.delegate have the wrong value for the currentTarget property. Currently it will be set the same as the target property, which is set to the can.Observe instance that originally triggered the change event. The currentTarget property should be set to the element on which the handler is executing (i.e. to which the delegate selector points).

The full family of target properties should be set as follows:

  • delegateTarget should be set to the observable on which the delegated event handler is registered.
  • currentTarget should be set to the observable to which the delegate selector points. (This observable should also be the context object of the event handler.)
  • target should be set to the observable from which the change event originated, before bubbling up the object tree.

It's important to have the right currentTarget configured when dealing with deeply nested observables or observable lists (i.e. tree structures) where one must apply different event handling logic depending on which 'level' of the data the event came from.

E.g. you could have templated event bindings in a can.Control that say:

"{tree} items add" : function( el, event, newVal, oldVal, prop ) {
  if ( event.currentTarget === event.target ) { 
    // Only take action for 'add' events that originated from
    // the top level `items` list.
  }
},

"{tree} items.*.items add" : function( el, event, newVal, oldVal, prop ) {
  // Take action for 'add' events that came from
  // the sub level items list.
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment