From 35e3c54b9b4944f025265a61257ee667541ab3d4 Mon Sep 17 00:00:00 2001 From: Steven Orvell Date: Mon, 11 Dec 2017 17:43:49 -0800 Subject: [PATCH 1/2] Apply `listeners` in constructor rather than `ready` Fixes #4394. This change allows elements to have "first crack" at their own events (via the `listeners` object) before handlers registered via `on-*` see events. This is both more expected and fixes an inconsistency with 1.x. --- lib/legacy/legacy-element-mixin.html | 6 +++++- lib/utils/gestures.html | 8 +++++++- test/unit/events-elements.html | 14 ++++++++++++++ test/unit/events.html | 17 +++++++++++++++++ 4 files changed, 43 insertions(+), 2 deletions(-) diff --git a/lib/legacy/legacy-element-mixin.html b/lib/legacy/legacy-element-mixin.html index 1a671a7274..3ce281c363 100644 --- a/lib/legacy/legacy-element-mixin.html +++ b/lib/legacy/legacy-element-mixin.html @@ -81,6 +81,11 @@ /** @type {Object} */ this._debouncers; this.created(); + // Ensure listeners are applied immediately so that they are + // added before declarative event listeners. This allows an element to + // decorate itself via an event prior to any declarative listeners + // seeing the event. Note, this ensures compatibility with 1.x ordering. + this._applyListeners(); } /** @@ -180,7 +185,6 @@ */ ready() { this._ensureAttributes(); - this._applyListeners(); super.ready(); } diff --git a/lib/utils/gestures.html b/lib/utils/gestures.html index 8bdff53952..e40bc262c1 100644 --- a/lib/utils/gestures.html +++ b/lib/utils/gestures.html @@ -579,7 +579,13 @@ */ setTouchAction: function(node, value) { if (HAS_NATIVE_TA) { - node.style.touchAction = value; + // NOTE: add touchAction async so that events can be added in + // custom element constructors. Otherwise we run afoult of custom + // elements restriction against settings attributes (style) in the + // constructor. + Polymer.Async.microTask.run(() => { + node.style.touchAction = value; + }); } node[TOUCH_ACTION] = value; }, diff --git a/test/unit/events-elements.html b/test/unit/events-elements.html index c5209f35e2..6df0e550c1 100644 --- a/test/unit/events-elements.html +++ b/test/unit/events-elements.html @@ -17,6 +17,8 @@ this._removed = []; }, handle: function(e) { + const order = e._handleOrder = e._handleOrder || []; + order.push(this.localName); this._handled[e.currentTarget.localName] = e.type; }, unlisten: function(node, eventName, handler) { @@ -51,6 +53,18 @@ + + + + +