Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updates for latest compiler (0.14.x), Halogen v6 and [email protected] #9

Merged
merged 3 commits into from
Jul 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,11 @@
"yarn.lock"
],
"dependencies": {
"purescript-string-parsers": "^5.0.0",
"purescript-halogen": "^5.0.0-rc.4"
"purescript-string-parsers": "^6.0.0",
"purescript-halogen": "^6.1.0"
},
"devDependencies": {
"purescript-psci-support": "^4.0.0",
"purescript-jest": "^0.3.0",
"purescript-debug": "^4.0.0"
"purescript-psci-support": "^5.0.0",
"purescript-debug": "^5.0.0"
}
}
7 changes: 4 additions & 3 deletions example/bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
"output"
],
"dependencies": {
"purescript-string-parsers": "^5.0.0",
"purescript-halogen": "^5.0.0-rc.4"
"purescript-string-parsers": "^6.0.0",
"purescript-jest": "^0.5.0",
"purescript-halogen": "^6.1.0"
},
"devDependencies": {
"purescript-psci-support": "^4.0.0"
"purescript-psci-support": "^5.0.0"
}
}
76 changes: 40 additions & 36 deletions example/src/App.purs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@ module App where

import Prelude

import Control.Monad.State (class MonadState)
import Data.Const (Const)
import Data.Maybe (Maybe(..))
import Effect.Aff.Class (class MonadAff)
import Halogen as H
import Halogen.HTML as HH
import Halogen.HTML.Events as HE
import Halogen.HTML.Properties as HP
import Html.Renderer.Halogen as PH

type Query :: forall k. k -> Type
type Query = Const Void

data Action = OnValueChange String
Expand Down Expand Up @@ -51,47 +53,49 @@ class_ = HP.class_ <<< HH.ClassName
style :: forall r i. String -> HP.IProp ("style" :: String | r) i
style = HP.attr (HH.AttrName "style")

render :: forall m. State -> H.ComponentHTML Action () m
render state =
HH.div [ class_ "grid" ]
[ HH.h2 [ class_ "header" ]
[ HH.text "purescript-html-parser-halogen example" ]
, HH.div [ class_ "col col-edit" ]
[ HH.h4_ [ HH.text "EDIT" ]
, HH.textarea
[ class_ "edit"
, HP.value state.value
, HE.onValueInput $ Just <<< OnValueChange
]
]
, HH.div [ class_ "col col-preview" ]
[ HH.h4_ [ HH.text "PREVIEW" ]
, HH.div [ class_ "preview" ]
[ PH.render_ state.value ]
]
, HH.div [ class_ "footer" ]
[ HH.a
[ HP.href demoSourceUrl] [HH.text "source code"]
, HH.text " Powered by "
, HH.img
[ HP.src "https://upload.wikimedia.org/wikipedia/commons/6/64/PureScript_Logo.png"
, style "width: 1rem; height: 1rem"
]
]
]
where
repoUrl = "https://github.com/rnons/purescript-html-parser-halogen"
demoSourceUrl = repoUrl <> "/tree/master/example"

app :: forall m. H.Component HH.HTML Query Unit Void m
app = H.mkComponent
component :: forall query input output m. MonadAff m => H.Component query input output m
component = H.mkComponent
{ initialState: const initialState
, render
, eval: H.mkEval $ H.defaultEval
{ handleAction = handleAction }
}
where

render state =
HH.div [ class_ "grid" ]
[ HH.h2 [ class_ "header" ]
[ HH.text "purescript-html-parser-halogen example" ]
, HH.div [ class_ "col col-edit" ]
[ HH.h4_ [ HH.text "EDIT" ]
, HH.textarea
[ class_ "edit"
, HP.value state.value
, HE.onValueInput \s -> OnValueChange s
]
]
, HH.div [ class_ "col col-preview" ]
[ HH.h4_ [ HH.text "PREVIEW" ]
, HH.div [ class_ "preview" ]
[ PH.render_ state.value ]
]
, HH.div [ class_ "footer" ]
[ HH.a
[ HP.href demoSourceUrl] [HH.text "source code"]
, HH.text " Powered by "
, HH.img
[ HP.src "https://upload.wikimedia.org/wikipedia/commons/6/64/PureScript_Logo.png"
, style "width: 1rem; height: 1rem"
]
]
]
where
repoUrl = "https://github.com/rnons/purescript-html-parser-halogen"
demoSourceUrl = repoUrl <> "/tree/master/example"

handleAction :: forall m. Action -> H.HalogenM State Action () Void m Unit
handleAction :: forall m.
MonadState State m =>
Action -> m Unit
handleAction = case _ of
OnValueChange value -> do
H.modify_ $ _ { value = value }
4 changes: 2 additions & 2 deletions example/src/Main.purs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import Prelude
import Effect (Effect)
import Halogen.Aff as HA
import Halogen.VDom.Driver (runUI)
import App (app)
import App (component)

main :: Effect Unit
main = HA.runHalogenAff do
body <- HA.awaitBody
runUI app unit body
runUI component unit body