I'm working with Leaflet.js
& Leaflet-Editable.js
there are a lot places where I need to respond to clicks on, creation of, etc. different types of map features differently. This function allows me to eschew if,else,if,else
blocks for these cases.
Example:
if(is(L.Marker, feature)){
setMarkerStyleActive(feature);
} else if(is(L.Polyline, feature)){
setPolylineStyleActive(feature);
} else if(is(L.Polygon, feature)){
setPolygonStyleActive(feature);
}
const setStyleActive = runByType(new Map([
[L.Marker, setMarkerStyleActive],
[L.Polyline, setPolylineStyleActive],
[L.Polygon, setPolygonStyleActive]
]);
//then when I need to use it
setStyleActive(thing);
not super useful if you only have 1 switch like above but with many it becomes useful