How could this example be fixed? It does not work out of the box, and as usual, PureScript error messages are not very helpful.
maybe this is the answer
I have tired and failed.
Reading the fora on the web, I see many examples of people lecturing frustrated noobs to learn the language first.
Can somebody provide example on how learning the language has helped him to solve this concrete problem?
I need to modify the counter example to provide the initial configuration to the component. That configuration has to change numerous times after deploying the app, each time the page loads or reloads.
I found how to pass value from main to initial halogen component.
But I am stuck at passing configuration to main. This seemed to be the answer:
Lucas DiCioccio’s Blog - How I write PureScript web-apps: Part-III
but so far it has been a frustrating experience, the code does not compile.
To make matters worse, I am sure sometimes compiler reports errors in the wrong places.
Here’s a version with minor changes to make it compile:
module Main where
import Prelude
import Data.Maybe (Maybe)
import Data.Traversable (traverse, traverse_)
import Effect (Effect)
import Web.DOM.Element (getAttribute)
import Web.HTML (window)
import Web.HTML.HTMLDocument (currentScript)
import Web.HTML.HTMLScriptElement as HTMLScript
import Web.HTML.Window (Window)
import Web.HTML.Window as Window
type TagInsertionConfig =
{ endpoint :: Maybe String
, apiKey :: Maybe String
}
readConfig :: Window -> Effect (Maybe TagInsertionConfig)
readConfig win = do
script <- currentScript =<< Window.document win
traverse go script
where
go script = do
let elem = HTMLScript.toElement script
{ endpoint: _, apiKey: _ }
<$> getAttribute "data-my-app--api-endpoint" elem
<*> getAttribute "data-my-app--api-key" elem
main :: Effect Unit
main = do
w <- window
readConfig w >>= traverse_ \config ->
?doStuffWithConfig config
Thank you very much. In the meantime I managed to come up with my version
Perhaps from your perspective, the changes were minor, but it took me five days to reach the solution.
Sorry, that wasn’t meant to downplay your efforts. I just meant I only did minimal fixes based on the errors the compiler gave me but didn’t check that it actually worked.
No, you were not downplaying my efforts.
I understand there is a different perspective here.