Index: pkg/polymer/lib/src/events.dart |
diff --git a/pkg/polymer/lib/src/events.dart b/pkg/polymer/lib/src/events.dart |
index ccf07861513ee26d3d4a6586cd810ce44d860f1d..881728a65c80619c0f5b6ff4d7480956229d3b5a 100644 |
--- a/pkg/polymer/lib/src/events.dart |
+++ b/pkg/polymer/lib/src/events.dart |
@@ -88,21 +88,28 @@ abstract class PolymerEventBindings { |
eventType = translated != null ? translated : eventType; |
return (model, node, oneTime) { |
- var handler = getEventHandler(null, node, path); |
- var sub = node.on[eventType].listen(handler); |
+ var eventHandler = |
+ Zone.current.bindUnaryCallback(getEventHandler(null, node, path)); |
+ // TODO(jakemac): Remove this indirection if/when JsFunction gets a |
+ // simpler constructor that doesn't pass this, http://dartbug.com/20545. |
+ var handler = new JsFunction.withThis((_, e) => eventHandler(e)); |
+ _PolymerGestures.callMethod( |
+ 'addEventListener', [node, eventType, handler]); |
if (oneTime) return null; |
- return new _EventBindable(sub, path); |
+ return new _EventBindable(path, node, eventType, handler); |
}; |
} |
} |
class _EventBindable extends Bindable { |
- StreamSubscription _sub; |
final String _path; |
+ final Node _node; |
+ final String _eventType; |
+ final JsFunction _handler; |
- _EventBindable(this._sub, this._path); |
+ _EventBindable(this._path, this._node, this._eventType, this._handler); |
// TODO(rafaelw): This is really pointless work. Aside from the cost |
// of these allocations, NodeBind is going to setAttribute back to its |
@@ -113,10 +120,8 @@ class _EventBindable extends Bindable { |
open(callback) => value; |
void close() { |
- if (_sub != null) { |
- _sub.cancel(); |
- _sub = null; |
- } |
+ _PolymerGestures.callMethod( |
+ 'removeEventListener', [_node, _eventType, _handler]); |
} |
} |