Skip to content

Commit b18a61e

Browse files
committed
Remove reduce in Playground querystring building
1 parent 9797966 commit b18a61e

File tree

2 files changed

+9
-20
lines changed

2 files changed

+9
-20
lines changed

src/Playground.mjs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1539,16 +1539,11 @@ function Playground$ControlPanel(Props) {
15391539
"code",
15401540
LzString.compressToEncodedURIComponent(editorCode.current)
15411541
]);
1542-
var querystring = Belt_Array.reduce(params, "", (function (acc, next) {
1543-
var value = next[1];
1544-
var key = next[0];
1545-
if (acc === "") {
1546-
return "?" + (key + ("=" + value));
1547-
} else {
1548-
return acc + ("&" + (key + ("=" + value)));
1549-
}
1550-
}));
1551-
var url = window.___location.origin + (router.route + querystring);
1542+
var querystring = params.map(function (param) {
1543+
return param[0] + "=" + param[1];
1544+
}).join("&");
1545+
console.log(querystring);
1546+
var url = window.___location.origin + router.route + "?" + querystring;
15521547
Next.Router.replace(router, url);
15531548
return url;
15541549
};

src/Playground.res

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1214,17 +1214,11 @@ module ControlPanel = {
12141214
("code", editorCode.current->LzString.compressToEncodedURIComponent),
12151215
)->ignore
12161216

1217-
let querystring = Belt.Array.reduce(params, "", (acc, next) => {
1218-
let (key, value) = next
1217+
let querystring =
1218+
params->Js.Array2.map(((key, value)) => key ++ "=" ++ value)->Js.Array2.joinWith("&")
1219+
Js.log(querystring)
12191220

1220-
if acc === "" {
1221-
"?" ++ (key ++ ("=" ++ value))
1222-
} else {
1223-
acc ++ ("&" ++ (key ++ ("=" ++ value)))
1224-
}
1225-
})
1226-
1227-
let url = origin ++ (router.route ++ querystring)
1221+
let url = origin ++ router.route ++ "?" ++ querystring
12281222
Next.Router.replace(router, url)
12291223
url
12301224
}

0 commit comments

Comments
 (0)