Skip to content

Commit fa0425b

Browse files
authored
Restore broken Components*HalogenHooks recipes (#283)
* Restore broken Components*HalogenHooks recipes * Add missing deps
1 parent 47fcee3 commit fa0425b

File tree

20 files changed

+60
-44
lines changed

20 files changed

+60
-44
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,10 @@ Running a web-compatible recipe:
9999
| | :heavy_check_mark: ([try](https://try.ps.ai/?github=JordanMartinez/purescript-cookbook/master/recipes/CatGifsHalogenHooks/src/Main.purs)) | [CatGifsHalogenHooks](recipes/CatGifsHalogenHooks) | A Halogen port of the ["HTTP - Cat GIFs" Elm Example](https://elm-lang.org/examples/cat-gifs). |
100100
| | :heavy_check_mark: ([try](https://try.ps.ai/?github=JordanMartinez/purescript-cookbook/master/recipes/CatGifsReactHooks/src/Main.purs)) | [CatGifsReactHooks](recipes/CatGifsReactHooks) | A React port of the ["HTTP - Cat GIFs" Elm Example](https://elm-lang.org/examples/cat-gifs). |
101101
| | :heavy_check_mark: ([try](https://try.ps.ai/?github=JordanMartinez/purescript-cookbook/master/recipes/ClockReactHooks/src/Main.purs)) | [ClockReactHooks](recipes/ClockReactHooks) | A React port of the ["User Interface - Clock" Elm Example](https://elm-lang.org/examples/clock). |
102+
| | :heavy_check_mark: ([try](https://try.ps.ai/?github=JordanMartinez/purescript-cookbook/master/recipes/ComponentsHalogenHooks/src/Main.purs)) | [ComponentsHalogenHooks](recipes/ComponentsHalogenHooks) | Demonstrates how to nest one Halogen-Hooks-based component inside another and send/receive queries between the two. |
103+
| | :heavy_check_mark: ([try](https://try.ps.ai/?github=JordanMartinez/purescript-cookbook/master/recipes/ComponentsInputHalogenHooks/src/Main.purs)) | [ComponentsInputHalogenHooks](recipes/ComponentsInputHalogenHooks) | Each time a parent re-renders, it will pass a new input value into the child, and the child will update accordingly. |
102104
| | :heavy_check_mark: ([try](https://try.ps.ai/?github=JordanMartinez/purescript-cookbook/master/recipes/ComponentsInputReactHooks/src/Main.purs)) | [ComponentsInputReactHooks](recipes/ComponentsInputReactHooks) | Each time the parent's state updates, it will pass a new prop value into the child, and the child will update accordingly. |
105+
| | :heavy_check_mark: ([try](https://try.ps.ai/?github=JordanMartinez/purescript-cookbook/master/recipes/ComponentsMultiTypeHalogenHooks/src/Main.purs)) | [ComponentsMultiTypeHalogenHooks](recipes/ComponentsMultiTypeHalogenHooks) | Demonstrates a component that can communicate with its children that have differing types. |
103106
| | :heavy_check_mark: ([try](https://try.ps.ai/?github=JordanMartinez/purescript-cookbook/master/recipes/ComponentsMultiTypeReactHooks/src/Main.purs)) | [ComponentsMultiTypeReactHooks](recipes/ComponentsMultiTypeReactHooks) | Demonstrates a parent component with several children components, each with different prop types. |
104107
| | :heavy_check_mark: ([try](https://try.ps.ai/?github=JordanMartinez/purescript-cookbook/master/recipes/ComponentsReactHooks/src/Main.purs)) | [ComponentsReactHooks](recipes/ComponentsReactHooks) | Demonstrates how to nest one React Hooks-based component inside another and send props from the parent to the child component. |
105108
| :heavy_check_mark: | :heavy_check_mark: ([try](https://try.ps.ai/?github=JordanMartinez/purescript-cookbook/master/recipes/DateTimeBasicsLog/src/Main.purs)) | [DateTimeBasicsLog](recipes/DateTimeBasicsLog) | This recipe shows how to use `purescript-datetime` library to create `Time`, `Date`, and `DateTime` values and adjust/diff them. |

broken/ComponentsHalogenHooks/spago.dhall

Lines changed: 0 additions & 11 deletions
This file was deleted.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{ name = "ComponentsHalogenHooks"
2+
, dependencies =
3+
[ "console"
4+
, "effect"
5+
, "halogen"
6+
, "halogen-hooks"
7+
, "maybe"
8+
, "prelude"
9+
, "psci-support"
10+
, "refs"
11+
, "tuples"
12+
]
13+
, packages = ../../packages.dhall
14+
, sources = [ "recipes/ComponentsHalogenHooks/src/**/*.purs" ]
15+
}

broken/ComponentsHalogenHooks/src/Main.purs renamed to recipes/ComponentsHalogenHooks/src/Main.purs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ module ComponentsHalogenHooks.Main where
33
import Prelude hiding (top)
44

55
import Data.Maybe (Maybe(..), maybe)
6-
import Data.Symbol (SProxy(..))
76
import Data.Tuple.Nested ((/\))
87
import Effect (Effect)
98
import Effect.Class (class MonadEffect)
@@ -14,18 +13,19 @@ import Halogen.Aff as HA
1413
import Halogen.HTML as HH
1514
import Halogen.HTML.Events as HE
1615
import Halogen.HTML.Properties as HP
17-
import Halogen.Hooks (Hooked, UseEffect, UseRef)
16+
import Halogen.Hooks (type (<>), Hook, UseEffect, UseRef)
1817
import Halogen.Hooks as Hooks
1918
import Halogen.VDom.Driver (runUI)
19+
import Type.Proxy (Proxy(..))
2020

2121
main :: Effect Unit
2222
main =
2323
HA.runHalogenAff do
2424
body <- HA.awaitBody
2525
void $ runUI containerComponent unit body
2626

27-
_button :: SProxy "button"
28-
_button = SProxy
27+
_button :: Proxy "button"
28+
_button = Proxy
2929

3030
containerComponent
3131
:: forall unusedQuery unusedInput unusedOutput anyMonad
@@ -37,7 +37,7 @@ containerComponent = Hooks.component \rec _ -> Hooks.do
3737
buttonState /\ buttonStateIdx <- Hooks.useState (Nothing :: Maybe Boolean)
3838
Hooks.pure $
3939
HH.div_
40-
[ HH.slot _button unit buttonComponent unit \_ -> Just do
40+
[ HH.slot _button unit buttonComponent unit \_ -> do
4141
Hooks.modify_ toggleCountIdx (_ + 1)
4242
, HH.p_
4343
[ HH.text ("Button has been toggled " <> show toggleCount <> " time(s)") ]
@@ -47,8 +47,8 @@ containerComponent = Hooks.component \rec _ -> Hooks.do
4747
<> (maybe "(not checked yet)" (if _ then "on" else "off") buttonState)
4848
<> ". "
4949
, HH.button
50-
[ HE.onClick \_ -> Just do
51-
mbBtnState <- Hooks.query rec.slotToken _button unit $ H.request IsOn
50+
[ HE.onClick \_ -> do
51+
mbBtnState <- Hooks.query rec.slotToken _button unit $ H.mkRequest IsOn
5252
Hooks.put buttonStateIdx mbBtnState
5353
]
5454
[ HH.text "Check now" ]
@@ -73,7 +73,7 @@ buttonComponent = Hooks.component \rec _ -> Hooks.do
7373
Hooks.pure $
7474
HH.button
7575
[ HP.title label
76-
, HE.onClick \_ -> Just do
76+
, HE.onClick \_ -> do
7777
newState <- Hooks.modify enabledIdx not
7878
Hooks.raise rec.outputToken $ Toggled newState
7979
]
@@ -82,7 +82,7 @@ buttonComponent = Hooks.component \rec _ -> Hooks.do
8282
useRenderCount
8383
:: forall m a
8484
. MonadEffect m
85-
=> Hooked m a (UseEffect (UseRef Int a)) Int
85+
=> Hook m (UseRef Int <> UseEffect <> a) Int
8686
useRenderCount = Hooks.do
8787
renders /\ rendersRef <- Hooks.useRef 1
8888
Hooks.captures {} Hooks.useTickEffect do
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)