Skip to content

Instantly share code, notes, and snippets.

@sebug sebug/Main

forked from anonymous/Main
Created Mar 1, 2015
What would you like to do?
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
You can’t perform that action at this time.