Skip to content

Instantly share code, notes, and snippets.

@sebug
Forked from anonymous/Main
Created March 1, 2015 13:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sebug/562853dbabdfee92e200 to your computer and use it in GitHub Desktop.
Save sebug/562853dbabdfee92e200 to your computer and use it in GitHub Desktop.
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