Skip to content
This repository has been archived by the owner on Mar 13, 2018. It is now read-only.

NodeBind should support binding to events #8

Closed
rafaelw opened this issue Dec 16, 2013 · 2 comments
Closed

NodeBind should support binding to events #8

rafaelw opened this issue Dec 16, 2013 · 2 comments

Comments

@rafaelw
Copy link
Contributor

rafaelw commented Dec 16, 2013

Polymer supports this following kind of thing:

<div on-click="{{ myClickHandler }}"></div>

It does this at the polymer-expressions layer. I think this is very common behavior and should be a concern of element's NodeBind.

Here's how I propose this work:

HTMLElement allows binding to 'on-', by setting up a binding to the event whose name is the first N non-whitespace characters following 'on-'. The behavior of the binding is to

addEventListener(name, function(e) { 
  var fn = observable.getValue();
  if (typeof fn == 'function')
    fn(e);
  else
    console.warn('cannot invoke non-function: ' + fn);
});

One thing to note here is that the bindingValue doesn't really need to be an observer, even though it is dynamic. It's sufficient to retrieve the value when the event is handled.

Thus the implementation of the element that handles the binding might not call open(), but only getValue() on the observable.

@rafaelw
Copy link
Contributor Author

rafaelw commented Dec 17, 2013

Also, appropos:

Polymer/polymer#368 (comment)

@rafaelw
Copy link
Contributor Author

rafaelw commented Dec 27, 2013

Fixed: 5030c46

@rafaelw rafaelw closed this as completed Dec 27, 2013
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant