Open rowanG077 opened 4 years ago
Seems like you want to call from server side code to code running in the browser. You will likely need WebSockets for this. I'm not much familiar with IHP, but I saw some WS lid is actually a dependency, yet I think that may be there for the hot code reloading and is not yet exposed by the APIs for devs. IHP is, from what I read in the docs, an old skool request-response based framework: going with WebSockets requires quite a bit different architecture on the server side.
Hey together :) Right now WebSockets aren't supported in IHP userland (it's planned).
@rowanG077 if you have a more specific example on what you want to do, maybe I can guide you in the right direction of how to do it the IHP-way.
How about using GHCJS with nix ?
IMO GHCJS is a bit too heavyweight for most use cases. We can solve a lot of use cases by offering something like Phoenix LiveViews. When an SPA is really needed, I'd take a look at using Elm. We could add an Recipe to the documentation on using Elm with IHP.
@mpscholten It's awesome. I'd love to see an example with API in IHP and ELM as the frontend.
Thanks for the quick responses. I have some peripheral hardware that can talk via serial. I can leverage this in a "standard" browser setting by using web serial to connect to it. In addition my goal was to plot data that comes from this serial port in real-time. I don't particularly want to implement a plotting library myself so instead I would want to use a mature JavaScript plotting library and just push my data to it via a JS FFI or something.
But from the discussion I understand that ihp is server-side only and it doesn't actually run code on the client side.
But from the discussion I understand that ihp is server-side only and it doesn't actually run code on the client side.
Maybe you could pass the serial data to the view via json and then plot it by including the script via the usual <script>
tag way?
IMO GHCJS is a bit too heavyweight for most use cases. We can solve a lot of use cases by offering something like Phoenix LiveViews. When an SPA is really needed, I'd take a look at using Elm. We could add an Recipe to the documentation on using Elm with IHP.
I think LiveViews fixes most of these cases.
I think GHCJS should be given a chance though; I would like to not use JS/Elm or anything else for cases where Liveviews do not work. But maybe it's a dream. Next of Elm I prefer Purescript if not Haskell.
I can't find this in the documentation. But I would like to call JS function (normal and async functions) from within ihp. Mainly to leverage the huge number of existing JavaScript libraries and also to call into the browser API's like file reading, local storage etc.
If this is possible could you provide an example or link to documentation on how I can achieve this?