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

Upgrade to halogen-5.0.0 #4

Merged
merged 6 commits into from
Jun 5, 2019
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
6 changes: 3 additions & 3 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
"docs"
],
"dependencies": {
"purescript-halogen": "^4.0.0",
"purescript-routing": "^8.0.0",
"purescript-foreign-object": "^1.0.0"
"purescript-halogen": "^5.0.0-rc.4",
"purescript-routing": "^9.0.0",
"purescript-foreign-object": "^2.0.0"
},
"devDependencies": {
"purescript-psci-support": "^4.0.0"
Expand Down
2 changes: 1 addition & 1 deletion examples/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
```
yarn
pulp -w build
pulp -w build -I ../src
yarn start
```
7 changes: 4 additions & 3 deletions examples/bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
"output"
],
"dependencies": {
"purescript-halogen": "^4.0.0",
"purescript-halogen-storybook": "*"
"purescript-halogen": "^5.0.0-rc.4",
"purescript-routing": "^9.0.0"
},
"devDependencies": {
"purescript-psci-support": "^4.0.0"
"purescript-psci-support": "^4.0.0",
"purescript-debug": "^4.0.0"
}
}
1 change: 1 addition & 0 deletions examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"scripts": {
"build": "pulp build --to output/Main/index.js && webpack --mode production --progress",
"pscid:build": "pulp build",
"postinstall": "bower install",
"start": "webpack-dev-server --mode development --progress"
},
"devDependencies": {
Expand Down
35 changes: 20 additions & 15 deletions examples/src/Example/Count.purs
Original file line number Diff line number Diff line change
Expand Up @@ -2,51 +2,56 @@ module Example.Count where

import Prelude

import Data.Const (Const)
import Data.Maybe (Maybe(..))

import Halogen as H
import Halogen.HTML as HH
import Halogen.HTML.Events as HE

data Query a
= Increase a
| Decrease a
type Query = Const Void

data Action
= Increase
| Decrease

type State = { value :: Int }

component :: forall m. H.Component HH.HTML Query Unit Void m
component = H.component
component = H.mkComponent
{ initialState: const initialState
, render
, eval
, receiver: const Nothing
, eval: H.mkEval $ H.defaultEval
{ handleAction = handleAction }
}
where

initialState :: State
initialState = { value: 0 }

render :: State -> H.ComponentHTML Query
render :: State -> H.ComponentHTML Action () m
render state =
HH.div_
[ HH.h3_
[ HH.text "A counter" ]
, HH.div_
[ HH.button
[ HE.onClick $ HE.input_ Increase ]
[ HE.onClick $ Just <<< const Increase ]
[ HH.text "+" ]
]
, HH.div_
[ HH.text $ show state.value ]
, HH.div_
[ HH.button
[ HE.onClick $ HE.input_ Decrease ]
[ HE.onClick $ Just <<< const Decrease ]
[ HH.text "-" ]
]
]

eval :: Query ~> H.ComponentDSL State Query Void m
eval (Increase next) =
H.modify (\state -> state { value = state.value + 1 }) $> next
eval (Decrease next) =
H.modify (\state -> state { value = state.value - 1 }) $> next
handleAction
:: forall m
. Action
-> H.HalogenM State Action () Void m Unit
handleAction Increase = do
H.modify_ (\state -> state { value = state.value + 1 })
handleAction Decrease = do
H.modify_ (\state -> state { value = state.value - 1 })
12 changes: 3 additions & 9 deletions examples/src/Example/Index.purs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ module Example.Index where
import Prelude

import Data.Const (Const)
import Data.Maybe (Maybe(..))
import Data.Newtype (unwrap)
import Halogen as H
import Halogen.HTML as HH
import Halogen.HTML.Properties as HP
Expand All @@ -16,7 +14,7 @@ type State = Unit
initialState :: State
initialState = unit

render :: State -> H.ComponentHTML Query
render :: forall m. State -> H.ComponentHTML Void () m
render state =
HH.div_
[ HH.h3_
Expand All @@ -31,12 +29,8 @@ render state =
]

component :: forall m. H.Component HH.HTML Query Unit Void m
component = H.component
component = H.mkComponent
{ initialState: const initialState
, render
, eval
, receiver: const Nothing
, eval: H.mkEval $ H.defaultEval
}
where
eval :: Query ~> H.ComponentDSL State Query Void m
eval = absurd <<< unwrap
24 changes: 15 additions & 9 deletions examples/src/Example/Input.purs
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,47 @@ module Example.Input where

import Prelude

import Data.Const (Const)
import Data.Maybe (Maybe(..))
import Halogen as H
import Halogen.HTML as HH
import Halogen.HTML.Events as HE
import Halogen.HTML.Properties as HP

data Query a = InputName String a
type Query = Const Void

data Action = InputName String

type State = { name :: String }

component :: forall m. H.Component HH.HTML Query Unit Void m
component = H.component
component = H.mkComponent
{ initialState: const initialState
, render
, eval
, receiver: const Nothing
, eval: H.mkEval $ H.defaultEval
{ handleAction = handleAction }
}
where

initialState :: State
initialState = { name: "" }

render :: State -> H.ComponentHTML Query
render :: State -> H.ComponentHTML Action () m
render state =
HH.div_
[ HH.h3_
[ HH.text "What's your name?" ]
, HH.input
[ HP.value state.name
, HE.onValueInput (HE.input InputName)
, HE.onValueInput $ Just <<< InputName
]
, HH.p_
[ HH.text $ "Hello, " <> state.name ]
]

eval :: Query ~> H.ComponentDSL State Query Void m
eval (InputName name next) = next <$ do
H.modify _{ name = name }
handleAction
:: forall m
. Action
-> H.HalogenM State Action () Void m Unit
handleAction (InputName name) = do
H.modify_ $ _{ name = name }
2 changes: 1 addition & 1 deletion examples/src/Main.purs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ stories :: forall m. Stories m
stories = Object.fromFoldable
[ Tuple "" $ proxy ExpIndex.component
, Tuple "count" $ proxy ExpCount.component
, Tuple "input" $ proxy ExpInput.component
, Tuple "Form|input" $ proxy ExpInput.component
]

logo :: HH.PlainHTML
Expand Down
21 changes: 17 additions & 4 deletions examples/src/Storybook.css
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,29 @@ body {

.Storybook-nav {
grid-area: nav;
list-style: none;
margin: 0;
padding: 0;
padding-top: 0.625rem;
overflow-y: auto;
font-size: 0.875rem;
background-color: #fafafa;
border-right: 1px solid rgba(0, 0, 0, 0.08);
}

.Storybook-nav-list {
list-style: none;
margin: 0;
padding: 0;
}

.Storybook-nav-section {
margin: 1rem 0;
}

.Storybook-nav-section-title {
color: #3a3a3a;
text-transform: uppercase;
font-weight: bold;
padding: 0.625rem 2rem;
}

.Storybook-link {
display: block;
text-decoration: none;
Expand Down
Loading