admin管理员组文章数量:1310466
I'm making a simple website with Yesod, and was trying to make my Julius more type-safe.
At the moment I have a JS function sendAction
that sends a POST
request with some JSON data to an endpoint defined with Yesod.
I've been using it like this:
sendAction({tag: "ClickMouse", button: "left"});
The action is Haskell looks like this:
data Action
= ActionClickMouse MouseButton
| ActionMoveMouse Int Int
deriving (FromJSON) ...
data MouseButton = MouseButtonLeft | MouseButtonRight
deriving ...
To make this more type-safe, I changed the Julius code to be:
sendAction('#{ActionClickMouse MouseButtonLeft}');
This works as expected (Note: when giving sendAction
an object it json-stringifies it, when giving it a string it just sends it without conversion).
Now, for the mouse move action I have:
const x = some calculation
const y = some calculation
sendAction({tag: "MoveMouse", x, y});
However, I can't figure out how to make this similarly more type safe (or if that's possible at all really). As the following just results in the error Variable not in scope: x
:
const x = some calculation
const y = some calculation
sendAction('#{ActionMoveMouse x y}');
Is there some way of using variables from JS in the Haskell interpolation?
本文标签: haskellHow to use JS variables in Julius interpolationStack Overflow
版权声明:本文标题:haskell - How to use JS variables in Julius interpolation? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741822392a2399443.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论