@tomhughes commented on this pull request.
> @@ -14,109 +14,85 @@ function RouteOutput(map) {
weight: 12
});
- let distanceUnits = "km_m";
- let downloadURL = null;
-
- function translateDistanceUnits(m) {
- if (distanceUnits === "mi_ft") {
- return [m / 0.3048, "ft", m / 1609.344, "mi"];
- } else if (distanceUnits === "mi_yd") {
- return [m / 0.9144, "yd", m / 1609.344, "mi"];
- } else {
- return [m, "m", m / 1000, "km"];
+ class UnitFormatter {
+ constructor(units) {
+ [[this.minorName, this.minorScale], [this.majorName, this.majorScale]] =
Object.entries(units);
Is this right? MDN says `Object.entries` iterates properties in order of
creation which I assume means in the order their written for multiple
properties in a constant but in that case the major units are first?
In any case I'm not sure that an interface that relies on the order of keys in
a dictionary is very intuitive...
> @@ -14,109 +14,85 @@ function RouteOutput(map) {
weight: 12
});
- let distanceUnits = "km_m";
- let downloadURL = null;
-
- function translateDistanceUnits(m) {
- if (distanceUnits === "mi_ft") {
- return [m / 0.3048, "ft", m / 1609.344, "mi"];
- } else if (distanceUnits === "mi_yd") {
- return [m / 0.9144, "yd", m / 1609.344, "mi"];
- } else {
- return [m, "m", m / 1000, "km"];
+ class UnitFormatter {
+ constructor(units) {
+ [[this.minorName, this.minorScale], [this.majorName, this.majorScale]] =
Object.entries(units);
+ };
Is there something special about a constructor in javascript that means it
needs a trailing semicolon but other methods don't?
> }
- }
+ totalDistance(m) {
Can we put blank lines between the methods please to make this a bit more
readable?
--
Reply to this email directly or view it on GitHub:
https://github.com/openstreetmap/openstreetmap-website/pull/7183#pullrequestreview-4587283215
You are receiving this because you are subscribed to this thread.
Message ID:
<openstreetmap/openstreetmap-website/pull/7183/review/[email protected]>_______________________________________________
rails-dev mailing list
[email protected]
https://lists.openstreetmap.org/listinfo/rails-dev