From 752a73cba7f80f332fd81b11a710fd2bd0bba460 Mon Sep 17 00:00:00 2001 From: Murray Lisook Date: Sat, 18 Jun 2016 08:42:57 -0500 Subject: [PATCH 1/2] Fix issue 299 MutationObserver for markers in Shadow DOM --- google-map.html | 11 ++++------- test/index.html | 1 + 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/google-map.html b/google-map.html index 372f0d7..281f574 100644 --- a/google-map.html +++ b/google-map.html @@ -144,7 +144,7 @@ * @event google-map-rightclick * @param {google.maps.MouseEvent} event The mouse event. */ - /** + /** * Fired when the map becomes idle after panning or zooming. * @event google-map-idle */ @@ -407,7 +407,7 @@ detached: function() { if (this._mutationObserver) { - this._mutationObserver.disconnect(); + this.unlisten(this.$.selector, 'items-changed', '_updateMarkers'); this._mutationObserver = null; } if (this._objectsMutationObserver) { @@ -480,10 +480,7 @@ if (this._mutationObserver) { return; } - this._mutationObserver = new MutationObserver(this._updateMarkers.bind(this)); - this._mutationObserver.observe(this.$.selector, { - childList: true - }); + this._mutationObserver = this.listen(this.$.selector, 'items-changed', '_updateMarkers'); }, _updateMarkers: function() { @@ -630,7 +627,7 @@ this.map.setZoom(Number(this.zoom)); } }, - + _idleEvent: function() { if (this.map) { this._forwardEvent('idle'); diff --git a/test/index.html b/test/index.html index dda0e72..c5f7743 100644 --- a/test/index.html +++ b/test/index.html @@ -14,6 +14,7 @@ 'google-map-update-pos.html', 'marker-basic.html', 'markers-add-remove.html', + 'markers-add-remove.html?dom=shadow', 'poly-basic.html' ]); From 32b01eccd4de4ef299f12fe81b896bdcffb9654b Mon Sep 17 00:00:00 2001 From: Murray Lisook Date: Sat, 18 Jun 2016 17:53:17 -0500 Subject: [PATCH 2/2] Rename property _mutationObserver to _markersChildrenListener --- google-map.html | 10 +++++----- test/markers-add-remove.html | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/google-map.html b/google-map.html index 281f574..805675d 100644 --- a/google-map.html +++ b/google-map.html @@ -406,9 +406,9 @@ }, detached: function() { - if (this._mutationObserver) { + if (this._markersChildrenListener) { this.unlisten(this.$.selector, 'items-changed', '_updateMarkers'); - this._mutationObserver = null; + this._markersChildrenListener = null; } if (this._objectsMutationObserver) { this._objectsMutationObserver.disconnect(); @@ -477,10 +477,10 @@ // watch for future updates to marker objects _observeMarkers: function() { // Watch for future updates. - if (this._mutationObserver) { + if (this._markersChildrenListener) { return; } - this._mutationObserver = this.listen(this.$.selector, 'items-changed', '_updateMarkers'); + this._markersChildrenListener = this.listen(this.$.selector, 'items-changed', '_updateMarkers'); }, _updateMarkers: function() { @@ -494,7 +494,7 @@ }.bind(this)); if (added.length === 0) { // set up observer first time around - if (!this._mutationObserver) { + if (!this._markersChildrenListener) { this._observeMarkers(); } return; diff --git a/test/markers-add-remove.html b/test/markers-add-remove.html index a20854e..55ec8bc 100644 --- a/test/markers-add-remove.html +++ b/test/markers-add-remove.html @@ -18,7 +18,7 @@