Skip to content

Repository files navigation

purescript-pha

a simple and fast Elm-like library also inspired by Halogen.

Documentation

Documentation is published on Pursuit

Minimal example

moduleExample.CounterwhereimportPreludeimportEffect (Effect)
importPha.App (sandbox)
importPha.Html (Html)
importPha.HtmlasHimportPha.Html.AttributesasPimportPha.Html.EventsasEtypeModel=IntdataMsg = Increment|DecrementinitModel
init = 0updateMsgModelModel
update Increment n = n + 1
update Decrement n = n - 1viewModelHtmlMsg
view counter = H.div []
[ H.button [E.onClick \_ → Decrement] [H.text "-"]
, H.span [] [H.text $ show counter]
, H.button [E.onClick \_ → Increment] [H.text "+"]
]
mainEffectUnit
main = sandbox {init, update, view, selector: "#root"}

Example with side effects

moduleExample.CounterwhereimportPreludeimportEffect (Effect)
importEffect.Aff (Aff)
importEffect.Random (randomInt)
importPha.App (app)
importPha.Html (Html)
importPha.HtmlasHimportPha.Html.AttributesasPimportPha.Html.EventsasEimportPha.Update (Update, liftEffect, put)
typeModel=IntdataMsg = RollDiceupdateMsgUpdateModelMsgAffUnit
update RollDice = put =<< liftEffect (randomInt 16)
viewStateHtmlMsg
view dice = H.div []
[ H.button [E.onClick \_ → RollDice] [H.text "Roll dice"]
, H.span [] [H.text $ show dice]
]
mainEffectUnit
main =
app
{ init: { model: 0, msg: JustRollDice }
, view
, update
, selector: "#root"
}

More examples

https://github.com/gbagan/purescript-pha-examples/tree/master/src

Some projects using purescript-pha

About

A simple and fast Elm-like library

Resources

Stars

13 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages