-
-
Notifications
You must be signed in to change notification settings - Fork 140
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Miso and jsaddle friendly wrapper around XHR #594
Comments
Perhaps the way to approach this is in Miso-agnostic way and reimplement the Feel free to close this if you consider it out of scope. |
Oh, I implemented something like this a while ago. On a basic level though |
I made 3 packages: It allows you to quickly set up your application for development. In opposite to A very basic wrapper around XHR that works with ghc and ghcjs. You can see it's usage here: https://github.com/DoctorRyner/haskell-app-reactor/blob/a13e26dd2def53538e520dd65f9c19118f6566b8/gui/src/Update.hs#L16 -- It's basic and easy to use
Http.send get { url = "/locale/ru.json" }
-- To extract the result you can use fromResp or fromRespDebug
fromResp resp model $ \locale -> model { locale = locale } You need just 2 constructors for your actions, that fires request and that catches it's result: https://github.com/DoctorRyner/haskell-app-reactor/blob/a13e26dd2def53538e520dd65f9c19118f6566b8/gui/src/Types.hs#L12 The It's like elm-css or styled-components, an example of usage is here: https://github.com/DoctorRyner/haskell-app-reactor/blob/a13e26dd2def53538e520dd65f9c19118f6566b8/gui/src/View.hs#L16 Where Also, like in Elm, ########## Just for notice, these are very low-quality packages that were made in haste for urgent order. So I just share some of my work that can be useful, I doubt that I will touch it ever again anyways https://github.com/DoctorRyner/miso-http/blob/master/src/Miso/Http.hs This can be too high-level and inflexible, but I think it's possible to use it as a reference to implement something more useful in a couple of days |
https://github.com/DoctorRyner/miso-http/blob/master/src/Miso/Http.hs looks good enough for my needs, I will try to use it, thanks! If I have any patches should I send them your way or just create a fork? |
There’s also servant-client-ghcjs and servant-client-jsaddle
…Sent from my iPhone
On Jun 14, 2020, at 12:47 PM, Bartosz Nitka ***@***.***> wrote:
@DoctorRyner
https://github.com/DoctorRyner/miso-http/blob/master/src/Miso/Http.hs looks good enough for my needs, I will try to use it, thanks!
If I have any patches should I send them your way or just create a fork?
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
I guess creating a fork would be a better option |
I went with https://github.com/haskell-servant/servant-jsaddle because it integrates nicely with servant. If anyone is going this route https://github.com/DarinM223/miso-fullstack is worth checking out. It bypasses CORS issues that arise because I've tried a similar approach before with running the server on the same port as With |
@niteria do you have any problem integrate servant-jsaddle with miso? I tried it but when I run
I don't understand why miso need |
Yeah, it took a bit of wrestling with Nix at a time. I wrote up what I learned here http://niteria.github.io/posts/nix-notes-overriding-haskell-packages/. I think you might find my
Note that it points to unmerged haskell-servant/servant-jsaddle@2ccf13d, for me the package was unusable without that patch. |
Is your feature request related to a problem? Please describe.
Currently, the Miso's XHR example can't be used directly with
jsaddle
, because it usesJavaScript.Web.XMLHttpRequest
which comes fromghcjs-base
which is JSFFI only.Describe the solution you'd like
There's an alternative that supports both
jsaddle
and JSFFI which is https://hackage.haskell.org/package/ghcjs-dom. Unfortunately, it's a more low-level API, a thin wrapper around JS functions.Reflex uses
ghcjs-dom
to provide some higher level functions: http://hackage.haskell.org/package/reflex-dom-core-0.6.0.0/docs/src/Reflex.Dom.Xhr.html#postJsonIt would be nice to have something similar for Miso.
The text was updated successfully, but these errors were encountered: