Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

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

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

rjgotten opened this issue Oct 23, 2012 · 0 comments
Labels

Comments

@rjgotten
Copy link

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
Labels
Projects
None yet
Development

No branches or pull requests

2 participants