Skip to content

Commit

Permalink
fix: removed the use of Weakmaps
Browse files Browse the repository at this point in the history
  • Loading branch information
khawarizmus committed Oct 1, 2023
1 parent f8f542b commit d55b228
Showing 1 changed file with 1 addition and 5 deletions.
6 changes: 1 addition & 5 deletions src/MethodRecommender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ import { CountryMethods } from './data/methods'
import type { LngLatLike } from './types/LangLatLike'
import type { Methods } from './types/Methods'

const methodsMap = new WeakMap<symbol, Methods[]>(
Object.entries(CountryMethods).map(([country, methods]) => [Symbol(country), methods])
)

/**
* recommend methods to use from given coordinate
* the methods are ranked by the most used to the least used
Expand All @@ -28,7 +24,7 @@ export function MethodRecommender(coordinatesOrLat: LngLatLike | number, longitu
const countryInfo = findCountryByCoordinate(
longitude ? [coordinatesOrLat as number, longitude] : getLngLat(coordinatesOrLat as LngLatLike)
)
return methodsMap.get(Symbol(countryInfo?.code))
return countryInfo?.code ? (CountryMethods as Record<string, Methods[]>)[countryInfo?.code] : undefined
}

function getLngLat(coordinates: LngLatLike): [number, number] {
Expand Down

0 comments on commit d55b228

Please sign in to comment.