From 41a0d5407c541319a435b4b003598896b5bdc494 Mon Sep 17 00:00:00 2001 From: Scott Farley Date: Mon, 18 Mar 2019 14:29:51 -0700 Subject: [PATCH 1/3] deduplicate result event emissions --- lib/index.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/index.js b/lib/index.js index 1ef7c0fa..64575d2d 100644 --- a/lib/index.js +++ b/lib/index.js @@ -54,6 +54,7 @@ function MapboxGeocoder(options) { this.options = extend({}, this.options, options); this.inputString = ''; this.fresh = true; + this.lastSelected = null; } MapboxGeocoder.prototype = { @@ -190,8 +191,12 @@ MapboxGeocoder.prototype = { }); } } - this._eventEmitter.emit('result', { result: selected }); - this.eventManager.select(selected, this); + if (selected.id !== this.lastSelected){ + console.log("gl:result") + this._eventEmitter.emit('result', { result: selected }); + this.eventManager.select(selected, this); + this.lastSelected = selected.id; + } } }, From 1f0b6baabbb2c46faffdd5ed9ad4f2ab5cb3b51a Mon Sep 17 00:00:00 2001 From: Scott Farley Date: Mon, 18 Mar 2019 14:53:05 -0700 Subject: [PATCH 2/3] update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5e190333..96bbb50f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ - Localize placeholder based on language set in constructor options [#150](https://github.com/mapbox/mapbox-gl-geocoder/issues/150) - `trackProximity` turned on by default [#195](https://github.com/mapbox/mapbox-gl-geocoder/issues/195) - Bump suggestions to v1.3.4 +- Fix duplicate event bug ## v3.1.4 From 5751660b2d992ddaa7b4c0e7060ce772ee4c6392 Mon Sep 17 00:00:00 2001 From: Scott Farley Date: Mon, 18 Mar 2019 17:12:51 -0700 Subject: [PATCH 3/3] respond to @katydecorah 's code review comments --- lib/index.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/index.js b/lib/index.js index 64575d2d..9e1f6ff2 100644 --- a/lib/index.js +++ b/lib/index.js @@ -192,7 +192,6 @@ MapboxGeocoder.prototype = { } } if (selected.id !== this.lastSelected){ - console.log("gl:result") this._eventEmitter.emit('result', { result: selected }); this.eventManager.select(selected, this); this.lastSelected = selected.id;