Package

purescript-pha

Repository
gbagan/purescript-pha
License
MIT
Uploaded by
gbagan
Published on
2020-03-16

Elm-like library

Documentation

Documentation is published on Pursuit

Minimal example

module Example.Counter where
import Prelude hiding (div)
import Effect (Effect)
import Pha (VDom, text)
import Pha (sandbox, attachTo)
import Pha.Elements (div, span, button)
import Pha.Events (onclick)

type Model = Int
data Msg = Increment | Decrement

init  Model
init = 0

update  Msg  Model  Model
update Increment n = n + 1
update Decrement n = n - 1

view  Model  VDom Msg
view counter = 
    div []
    [   button [onclick Decrement] [text "-"]
    ,   span [] [text $ show counter]
    ,   button [onclick Increment] [text "+"]
    ]

main  Effect Unit
main = sandbox { init, update, view} # attachTo "root"

Other examples

Counter2 (delayed action, raw events) Code | Demo

Randomness (+ animation) Code | Demo

Decoder (decoding events) Code | Demo

Inputs (event effects, text and checkbox inputs) Code | Demo

Cats (HTTP, json) Code | Demo

Routing Code | Demo