26
loading...
This website collects cookies to deliver better user experience
[email protected]
. Except for his React version, his code ran today on Rescript and ReasonML latest. You can see what he built at https://scottcheng.github.io/si-reason/.let (state, dispatch) = React.useReducer((_, action) =>
switch action {
| UpdateColumnPositions => {
columnPositions: emptyColumnPositions
|> Array.mapi((x, row) =>
row |> Array.mapi((y, _) => {
let rect = ReactDOM.domElementToObj(
getElementById(BoardBase.markerId(x, y)),
)["getBoundingClientRect"]()
(rect["left"], rect["top"])
})
),
}
}
, {columnPositions: emptyColumnPositions})
var match = React.useReducer((function (param, action) {
return {
columnPositions: $$Array.mapi((function (x, row) {
return $$Array.mapi((function (y, param) {
var rect = document.getElementById(BoardBase$SiReason.markerId(x, y)).getBoundingClientRect();
return [
rect.left,
rect.top
];
}), row);
}), emptyColumnPositions)
};
}), {
columnPositions: emptyColumnPositions
});
React.useReducer(
(_, action) =>
switch (action) {
| UpdateColumnPositions => {
columnPositions:
emptyColumnPositions
|> Array.mapi((x, row) =>
row
|> Array.mapi((y, _) => {
let rect =
ReactDOM.domElementToObj(
getElementById(BoardBase.markerId(x, y)),
)##getBoundingClientRect();
(rect##left, rect##top);
})
),
}
},
{columnPositions: emptyColumnPositions},
);
var match = React.useReducer((function (param, action) {
return {
columnPositions: $$Array.mapi((function (x, row) {
return $$Array.mapi((function (y, param) {
var rect = document.getElementById(BoardBase$SiReason.markerId(x, y)).getBoundingClientRect();
return [
rect.left,
rect.top
];
}), row);
}), emptyColumnPositions)
};
}), {
columnPositions: emptyColumnPositions
});
npx rescript convert -all
which is documented here:$ npx rescript convert -all 🔥
— ReScript (@rescriptlang) June 30, 2021In a dynamic language such as JS, currying would be dangerous, since accidentally forgetting to pass an argument doesn't error at compile time
correct
Javascript while the Rescript compiler does not. Anyone with an idea on why this is happening, please do share. I would love some feedback on it.(. )
as used here, in function application, means the function should be called with an uncurried calling convention.
When used in a function type, like the type of resolve
here, (. 'a) => unit
, it means the function is uncurried.
Ok, so what the hell does that mean…
let rect = ReactDOM.domElementToObj(
getElementById(BoardBase.markerId(x, y)),
)["getBoundingClientRect"](.)
(rect["left"], rect["top"])
(.)
after getBoundingClientRect
. That is how you uncurry a function in both ReasonML and Rescript though the ReasonML version does not require it. It happens automatically. I guess this means that Rescript is mostly
curried by default. Again, if you need to uncurry
a function you need to add the dot as shown.