From 27c0c1c0d32a999f5bf51eb25efb14868ab4a8bf Mon Sep 17 00:00:00 2001 From: Scott Farley Date: Thu, 21 Feb 2019 13:00:12 -0800 Subject: [PATCH] fix -1 bug --- CHANGELOG.md | 4 ++++ lib/events.js | 3 ++- package.json | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 718e7327..cc0dc233 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## v3.1.3 + +- Fix bug where events were logging -1 as resultIndex + ## v3.1.2 - Enable interaction event logging diff --git a/lib/events.js b/lib/events.js index de86d122..0593155b 100644 --- a/lib/events.js +++ b/lib/events.js @@ -44,9 +44,10 @@ MapboxEventManager.prototype = { var resultIndex = this.getSelectedIndex(selected, geocoder); var payload = this.getEventPayload('search.select', geocoder); payload.resultIndex = resultIndex; - if (resultIndex === this.lastSentIndex && payload.queryString === this.lastSentInput) { + if ((resultIndex === this.lastSentIndex && payload.queryString === this.lastSentInput) || resultIndex == -1) { // don't log duplicate events if the user re-selected the same feature on the same search if (callback) return callback(); + else return; } this.lastSentIndex = resultIndex; this.lastSentInput = payload.queryString; diff --git a/package.json b/package.json index 9edb8dcf..735428aa 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@mapbox/mapbox-gl-geocoder", - "version": "3.1.2", + "version": "3.1.3", "description": "A geocoder control for Mapbox GL JS", "main": "lib/index.js", "style": "lib/mapbox-gl-geocoder.css",