Skip to content

Commit

Permalink
Merge pull request #218 from mapbox/deduplicate-result-event
Browse files Browse the repository at this point in the history
Deduplicate result event emissions (#99)
  • Loading branch information
Scott Farley authored Mar 19, 2019
2 parents 6c6c98a + 5751660 commit 1c44b72
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 6 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ function MapboxGeocoder(options) {
this.options = extend({}, this.options, options);
this.inputString = '';
this.fresh = true;
this.lastSelected = null;
}

MapboxGeocoder.prototype = {
Expand Down Expand Up @@ -190,8 +191,11 @@ MapboxGeocoder.prototype = {
});
}
}
this._eventEmitter.emit('result', { result: selected });
this.eventManager.select(selected, this);
if (selected.id !== this.lastSelected){
this._eventEmitter.emit('result', { result: selected });
this.eventManager.select(selected, this);
this.lastSelected = selected.id;
}
}
},

Expand Down

0 comments on commit 1c44b72

Please sign in to comment.