Skip to content

Instantly share code, notes, and snippets.

/Main

Created March 1, 2015 13:40
Show Gist options
  • Save anonymous/64ec4a87bd5a713ac058 to your computer and use it in GitHub Desktop.
Save anonymous/64ec4a87bd5a713ac058 to your computer and use it in GitHub Desktop.
Integrating the XHR module with purescript-thermite
module Main where
import Debug.Trace
import Network.XHR
import qualified Thermite as T
import qualified Thermite.Html as T
import qualified Thermite.Html.Elements as T
import qualified Thermite.Action as T
import qualified Thermite.Types as T
type State = { message:: String }
data Action = LoadData
spec :: T.Spec (T.Action _ State) State Unit Action
spec = T.simpleSpec initialState performAction render
# T.componentWillMount LoadData
render :: T.Render State Unit Action
render ctx st _ = T.div' [ T.text st.message ]
loadSetState :: forall eff. (State -> EffAjax (trace :: Trace | eff) Unit) -> EffAjax (trace:: Trace | eff) Unit
loadSetState f = do
get defaultAjaxOptions
{ onReadyStateChange = onSuccess $ \response -> do
txt <- getResponseText response
f { message: txt }
} "/api/values" {}
return unit
performAction :: T.PerformAction Unit Action (T.Action _ State)
performAction _ LoadData = T.asyncSetState loadSetState
initialState :: State
initialState = { message: "Oh, hai" }
main = do
let cl = T.createClass spec
T.render cl unit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment