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

Simplify ComponentsHalogenHooks #252

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
Simplify ComponentsHalogenHooks
  • Loading branch information
milesfrain committed Dec 7, 2020
commit 95da82b6852893c1a23872aa381428026a0927be
9 changes: 4 additions & 5 deletions recipes/ComponentsHalogenHooks/src/Main.purs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module ComponentsHalogenHooks.Main where

import Prelude hiding (top)
import Prelude

import Data.Maybe (Maybe(..), maybe)
import Data.Symbol (SProxy(..))
Expand Down Expand Up @@ -49,12 +49,11 @@ containerComponent = Hooks.component \rec _ -> Hooks.do
]
]

data ButtonMessage = Toggled Boolean
data ButtonQuery a = IsOn (Boolean -> a)

buttonComponent
:: forall unusedInput anyMonad
. H.Component HH.HTML ButtonQuery unusedInput ButtonMessage anyMonad
. H.Component HH.HTML ButtonQuery unusedInput Unit anyMonad
buttonComponent = Hooks.component \rec _ -> Hooks.do
enabled /\ enabledIdx <- Hooks.useState false
Hooks.useQuery rec.queryToken case _ of
Expand All @@ -66,7 +65,7 @@ buttonComponent = Hooks.component \rec _ -> Hooks.do
HH.button
[ HP.title label
, HE.onClick \_ -> Just do
newState <- Hooks.modify enabledIdx not
Hooks.raise rec.outputToken $ Toggled newState
_ <- Hooks.modify enabledIdx not
Hooks.raise rec.outputToken unit
]
[ HH.text label ]