Skip to content

Commit 27befa1

Browse files
Update for Halogen 6
1 parent 256d09d commit 27befa1

9 files changed

Lines changed: 56 additions & 176 deletions

File tree

bower.json

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
{
22
"name": "purescript-halogen-select",
33
"homepage": "https://github.com/citizennet/purescript-halogen-select",
4-
"authors": [
5-
"Thomas Honeyman <hello@thomashoneyman.com>"
6-
],
4+
"authors": ["Thomas Honeyman <hello@thomashoneyman.com>"],
75
"description": "Building blocks for common selection user interfaces in PureScript & Halogen",
86
"keywords": [
97
"purescript",
@@ -17,7 +15,7 @@
1715
],
1816
"repository": {
1917
"type": "git",
20-
"url": "git://github.com/citizennet/purescript-halogen-select.git"
18+
"url": "https://github.com/citizennet/purescript-halogen-select.git"
2119
},
2220
"license": "Apache-2.0",
2321
"ignore": [
@@ -31,12 +29,12 @@
3129
"generated-docs"
3230
],
3331
"dependencies": {
34-
"purescript-halogen": "^5.0.0-rc.4",
35-
"purescript-record": "^2.0.0"
32+
"purescript-halogen": "^6.0.0",
33+
"purescript-record": "^3.0.0"
3634
},
3735
"devDependencies": {
38-
"purescript-debug": "^4.0.0",
39-
"purescript-affjax": "^9.0.0",
40-
"purescript-argonaut": "^6.0.0"
36+
"purescript-debug": "^5.0.0",
37+
"purescript-affjax": "^12.0.0",
38+
"purescript-argonaut": "^8.0.0"
4139
}
4240
}

examples/Components/Dropdown.purs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ type Input =
3131
, buttonLabel :: String
3232
}
3333

34-
component :: H.Component HH.HTML S.Query' Input Message Aff
34+
component :: H.Component S.Query' Input Message Aff
3535
component = S.component input $ S.defaultSpec
3636
{ render = render
3737
, handleEvent = handleEvent

examples/Components/Typeahead.purs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@ module Components.Typeahead where
22

33
import Prelude
44

5+
import Affjax (printError)
56
import Affjax as AX
67
import Affjax.ResponseFormat as AR
78
import Components.Dropdown as D
8-
import Data.Argonaut.Decode ((.:), decodeJson)
9+
import Data.Argonaut.Decode (decodeJson, printJsonDecodeError, (.:))
910
import Data.Array (mapWithIndex, filter, (:), (!!), length, null, difference)
10-
import Data.Foldable (for_)
1111
import Data.Bifunctor (lmap)
12+
import Data.Foldable (for_)
1213
import Data.Maybe (Maybe(..), maybe)
1314
import Data.Monoid (guard)
14-
import Data.Symbol (SProxy(..))
1515
import Data.Time.Duration (Milliseconds(..))
1616
import Data.Traversable (traverse)
1717
import Effect.Aff (Aff)
@@ -23,6 +23,7 @@ import Internal.CSS (class_, classes_, whenElem)
2323
import Internal.RemoteData as RD
2424
import Select as S
2525
import Select.Setters as SS
26+
import Type.Proxy (Proxy(..))
2627

2728
type Slot =
2829
S.Slot Query ChildSlots Message
@@ -46,7 +47,7 @@ data Message
4647
type ChildSlots =
4748
( dropdown :: D.Slot Unit )
4849

49-
component :: H.Component HH.HTML (S.Query Query ChildSlots) Unit Message Aff
50+
component :: H.Component (S.Query Query ChildSlots) Unit Message Aff
5051
component = S.component (const input) $ S.defaultSpec
5152
{ render = render
5253
, handleAction = handleAction
@@ -148,7 +149,7 @@ component = S.component (const input) $ S.defaultSpec
148149
closeButton item =
149150
HH.span
150151
[ class_ "Location__closeButton"
151-
, HE.onClick \_ -> Just $ S.Action $ Remove item
152+
, HE.onClick \_ -> S.Action $ Remove item
152153
]
153154
[ HH.text "×" ]
154155

@@ -164,8 +165,8 @@ component = S.component (const input) $ S.defaultSpec
164165
renderDropdown = whenElem (st.visibility == S.On) \_ ->
165166
HH.slot _dropdown unit D.component dropdownInput handler
166167
where
167-
_dropdown = SProxy :: SProxy "dropdown"
168-
handler msg = Just $ S.Action $ HandleDropdown msg
168+
_dropdown = Proxy :: Proxy "dropdown"
169+
handler msg = S.Action $ HandleDropdown msg
169170
dropdownInput = { items: [ "Earth", "Mars" ], buttonLabel: "Human Planets" }
170171

171172
renderContainer = whenElem (st.visibility == S.On) \_ ->
@@ -215,5 +216,8 @@ type Location =
215216
searchLocations :: String -> Aff (RD.RemoteData String (Array Location))
216217
searchLocations search = do
217218
res <- AX.get AR.json ("https://swapi.co/api/planets/?search=" <> search)
218-
let body = lmap AR.printResponseFormatError res.body
219-
pure $ RD.fromEither $ traverse decodeJson =<< (_ .: "results") =<< decodeJson =<< body
219+
pure $ RD.fromEither $ traverse (lmap printJsonDecodeError <<< decodeJson)
220+
=<< (lmap printJsonDecodeError <<< (_ .: "results"))
221+
=<< (lmap printJsonDecodeError <<< decodeJson)
222+
<<< _.body
223+
=<< (lmap printError res)

examples/Internal/Proxy.purs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,33 +12,34 @@ import Data.Const (Const(..))
1212
import Data.Coyoneda (Coyoneda, unCoyoneda)
1313
import Data.Maybe (Maybe(..))
1414
import Data.Newtype (un)
15-
import Data.Symbol (SProxy(..))
1615
import Halogen as H
1716
import Halogen.HTML as HH
17+
import Type.Proxy (Proxy(..))
1818

19+
data ProxyS :: (Type -> Type) -> Type -> Type -> Type
1920
data ProxyS f i a
2021
= Query (Coyoneda f a)
2122

2223
-- | A proxy that hides both the Query and Message of wrapped component.
2324
proxy
2425
:: forall f i o m
25-
. H.Component HH.HTML f i o m
26-
-> H.Component HH.HTML (ProxyS (Const Void) i) i Void m
26+
. H.Component f i o m
27+
-> H.Component (ProxyS (Const Void) i) i Void m
2728
proxy = proxyEval (const (absurd <<< un Const))
2829

2930
proxyEval
3031
:: forall f g i o m
3132
. (forall a b. (b -> a) -> g b -> H.HalogenM i Void (child :: H.Slot f o Unit) Void m a)
32-
-> H.Component HH.HTML f i o m
33-
-> H.Component HH.HTML (ProxyS g i) i Void m
33+
-> H.Component f i o m
34+
-> H.Component (ProxyS g i) i Void m
3435
proxyEval evalQuery component = H.mkComponent
3536
{ initialState: identity
3637
, render
3738
, eval: H.mkEval $ H.defaultEval { handleQuery = handleQuery }
3839
}
3940
where
4041
render :: i -> H.ComponentHTML Void (child :: H.Slot f o Unit) m
41-
render i = HH.slot (SProxy :: SProxy "child") unit component i (const Nothing)
42+
render i = HH.slot_ (Proxy :: Proxy "child") unit component i
4243

4344
handleQuery :: forall a. ProxyS g i a -> H.HalogenM i Void (child :: H.Slot f o Unit) Void m (Maybe a)
4445
handleQuery (Query iq) = Just <$> unCoyoneda evalQuery iq

examples/Main.purs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@ module Main where
22

33
import Prelude
44

5+
import Components.Dropdown as Dropdown
6+
import Components.Typeahead as Typeahead
57
import Data.Array (zipWith)
68
import Data.Const (Const)
79
import Data.Map as M
810
import Data.Maybe (Maybe(..), fromMaybe)
9-
import Data.Symbol (SProxy(..))
1011
import Data.Traversable (for_, sequence, traverse)
1112
import Data.Tuple (Tuple(..))
12-
import Components.Typeahead as Typeahead
13-
import Components.Dropdown as Dropdown
1413
import Effect (Effect)
1514
import Effect.Aff (Aff)
1615
import Effect.Class (liftEffect)
@@ -19,6 +18,7 @@ import Halogen.Aff as HA
1918
import Halogen.HTML as HH
2019
import Halogen.VDom.Driver (runUI)
2120
import Internal.Proxy (ProxyS, proxy)
21+
import Type.Proxy (Proxy(..))
2222
import Web.DOM.Element (getAttribute)
2323
import Web.DOM.NodeList (toArray)
2424
import Web.DOM.ParentNode (QuerySelector(..), querySelectorAll)
@@ -42,15 +42,15 @@ main = HA.runHalogenAff do
4242
-- Routes
4343

4444
type Components
45-
= M.Map String (H.Component HH.HTML (ProxyS (Const Void) Unit) Unit Void Aff)
45+
= M.Map String (H.Component (ProxyS (Const Void) Unit) Unit Void Aff)
4646

4747
routes :: Components
4848
routes = M.fromFoldable
4949
[ Tuple "typeahead" $ proxy typeahead
5050
, Tuple "dropdown" $ proxy dropdown
5151
]
5252

53-
app :: H.Component HH.HTML (Const Void) String Void Aff
53+
app :: H.Component (Const Void) String Void Aff
5454
app = H.mkComponent
5555
{ initialState: identity
5656
, render
@@ -59,7 +59,7 @@ app = H.mkComponent
5959
where
6060
render st = M.lookup st routes # case _ of
6161
Nothing -> HH.div_ []
62-
Just component -> HH.slot (SProxy :: SProxy "child") unit component unit absurd
62+
Just component -> HH.slot (Proxy :: Proxy "child") unit component unit absurd
6363

6464
----------
6565
-- Selection Helpers
@@ -83,23 +83,23 @@ selectElements { query, attr } = do
8383
----------
8484
-- Components
8585

86-
dropdown :: forall t0 t1 t2. H.Component HH.HTML t0 t1 t2 Aff
86+
dropdown :: forall t0 t1 t2. H.Component t0 t1 t2 Aff
8787
dropdown = H.mkComponent
8888
{ initialState: const unit
8989
, render: \_ ->
9090
HH.slot label unit Dropdown.component input \_ -> Nothing
9191
, eval: H.mkEval H.defaultEval
9292
}
9393
where
94-
label = SProxy :: SProxy "dropdown"
94+
label = Proxy :: Proxy "dropdown"
9595
input = { items: [ "Chris", "Forest", "Dave" ], buttonLabel: "Choose a character" }
9696

97-
typeahead :: forall t0 t1 t2. H.Component HH.HTML t0 t1 t2 Aff
97+
typeahead :: forall t0 t1 t2. H.Component t0 t1 t2 Aff
9898
typeahead = H.mkComponent
9999
{ initialState: const unit
100100
, render: \_ ->
101101
HH.slot label unit Typeahead.component unit \_ -> Nothing
102102
, eval: H.mkEval H.defaultEval
103103
}
104104
where
105-
label = SProxy :: SProxy "typeahead"
105+
label = Proxy :: Proxy "typeahead"

package.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@
99
"postinstall": "bower i --silent"
1010
},
1111
"devDependencies": {
12-
"bower": "^1.8.8",
13-
"npm-check-updates": "^3.1.0",
14-
"pulp": "12.3.1",
15-
"purescript": "0.12.3"
12+
"bower": "^1.8.12",
13+
"pulp": "15.0.0",
14+
"purescript": "0.14.0"
1615
}
1716
}

src/Select.purs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ type Input st =
116116
}
117117

118118
type Component query slots input msg m =
119-
H.Component HH.HTML (Query query slots) input msg m
119+
H.Component (Query query slots) input msg m
120120

121121
type ComponentHTML action slots m =
122122
H.ComponentHTML (Action action) slots m
@@ -184,7 +184,7 @@ component
184184
=> Row.Lacks "highlightedIndex" st
185185
=> (input -> Input st)
186186
-> Spec st query action slots input msg m
187-
-> H.Component HH.HTML (Query query slots) input msg m
187+
-> H.Component (Query query slots) input msg m
188188
component mkInput spec = H.mkComponent
189189
{ initialState: initialState <<< mkInput
190190
, render: spec.render

src/Select/Setters.purs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
-- | below.
55
module Select.Setters where
66

7-
import Prelude (append, ($), (<<<))
7+
import Prelude (append)
88

99
import Data.Maybe (Maybe(..))
1010
import Halogen as H
@@ -41,10 +41,10 @@ setToggleProps
4141
. Array (HP.IProp (ToggleProps props) (Action act))
4242
-> Array (HP.IProp (ToggleProps props) (Action act))
4343
setToggleProps = append
44-
[ HE.onFocus \_ -> Just $ SetVisibility On
45-
, HE.onMouseDown $ Just <<< ToggleClick
46-
, HE.onKeyDown $ Just <<< Key
47-
, HE.onBlur \_ -> Just $ SetVisibility Off
44+
[ HE.onFocus \_ -> SetVisibility On
45+
, HE.onMouseDown ToggleClick
46+
, HE.onKeyDown Key
47+
, HE.onBlur \_ -> SetVisibility Off
4848
, HP.tabIndex 0
4949
, HP.ref (H.RefLabel "select-input")
5050
]
@@ -75,11 +75,11 @@ setInputProps
7575
. Array (HP.IProp (InputProps props) (Action act))
7676
-> Array (HP.IProp (InputProps props) (Action act))
7777
setInputProps = append
78-
[ HE.onFocus \_ -> Just $ SetVisibility On
79-
, HE.onKeyDown $ Just <<< Key
80-
, HE.onValueInput $ Just <<< Search
81-
, HE.onMouseDown \_ -> Just $ SetVisibility On
82-
, HE.onBlur \_ -> Just $ SetVisibility Off
78+
[ HE.onFocus \_ -> SetVisibility On
79+
, HE.onKeyDown Key
80+
, HE.onValueInput Search
81+
, HE.onMouseDown \_ -> SetVisibility On
82+
, HE.onBlur \_ -> SetVisibility Off
8383
, HP.tabIndex 0
8484
, HP.ref (H.RefLabel "select-input")
8585
]
@@ -111,8 +111,8 @@ setItemProps
111111
-> Array (HP.IProp (ItemProps props) (Action act))
112112
-> Array (HP.IProp (ItemProps props) (Action act))
113113
setItemProps index = append
114-
[ HE.onMouseDown \ev -> Just (Select (Index index) (Just ev))
115-
, HE.onMouseOver \_ -> Just $ Highlight (Index index)
114+
[ HE.onMouseDown \ev -> Select (Index index) (Just ev)
115+
, HE.onMouseOver \_ -> Highlight (Index index)
116116
]
117117

118118
-- | A helper function that augments an array of `IProps` with a `MouseDown`
@@ -124,4 +124,4 @@ setContainerProps
124124
. Array (HP.IProp (onMouseDown :: ME.MouseEvent | props) (Action act))
125125
-> Array (HP.IProp (onMouseDown :: ME.MouseEvent | props) (Action act))
126126
setContainerProps = append
127-
[ HE.onMouseDown $ Just <<< PreventClick ]
127+
[ HE.onMouseDown PreventClick ]

0 commit comments

Comments
 (0)