Skip to content

Commit a15f154

Browse files
calculate score early and expose it via API
1 parent aad4f4c commit a15f154

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

wtp/locationSelector.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class LocationSelector {
6262
}
6363

6464
getBestLocationId(locations) {
65-
let selected = locations.reduce((acc, cur) => acc && this.getLocationScore(acc) < this.getLocationScore(cur) ? acc : cur);
65+
let selected = locations.reduce((acc, cur) => acc && acc.score < cur.score ? acc : cur);
6666
return selected.location;
6767
}
6868

@@ -82,6 +82,9 @@ class LocationSelector {
8282
return
8383
}
8484

85+
// enrich locations with our internal score
86+
filtered.forEach((location) => { location.score = this.getLocationScore(location); });
87+
8588
this.location = this.getBestLocationId(filtered);
8689
this.cachedAllLocations = filtered;
8790
this.lastUpdated = Date.now();

0 commit comments

Comments
 (0)