Remove useless example code (child components A B and C).

master
Philippe Pittoli 9 months ago
parent 09b2908403
commit 7576bc682c

@ -1,51 +0,0 @@
module App.ComponentA where
import Prelude
import Data.Maybe (Maybe(..))
import Halogen as H
import Halogen.HTML as HH
import Halogen.HTML.Events as HE
type Slot = H.Slot Query Void
data Query a = IsOn (Boolean -> a)
data Action = Toggle
type State = Boolean
component :: forall i o m. H.Component Query i o m
component =
H.mkComponent
{ initialState
, render
, eval: H.mkEval $ H.defaultEval
{ handleAction = handleAction
, handleQuery = handleQuery
}
}
initialState :: forall i. i -> State
initialState _ = false
render :: forall m. State -> H.ComponentHTML Action () m
render state =
HH.div_
[ HH.p_ [ HH.text "Toggle me!" ]
, HH.button
[ HE.onClick \_ -> Toggle ]
[ HH.text (if state then "On" else "Off") ]
]
handleAction :: forall o m. Action -> H.HalogenM State Action () o m Unit
handleAction = case _ of
Toggle ->
H.modify_ not
handleQuery :: forall o m a. Query a -> H.HalogenM State Action () o m (Maybe a)
handleQuery = case _ of
IsOn k -> do
enabled <- H.get
pure (Just (k enabled))

@ -1,53 +0,0 @@
module App.ComponentB where
import Prelude
import Data.Maybe (Maybe(..))
import Halogen as H
import Halogen.HTML as HH
import Halogen.HTML.Events as HE
type Slot = H.Slot Query Void
data Query a = GetCount (Int -> a)
data Action = Increment
type State = Int
component :: forall i o m. H.Component Query i o m
component =
H.mkComponent
{ initialState
, render
, eval: H.mkEval $ H.defaultEval
{ handleAction = handleAction
, handleQuery = handleQuery
}
}
initialState :: forall i. i -> State
initialState _ = 0
render :: forall m. State -> H.ComponentHTML Action () m
render state =
HH.div_
[ HH.p_
[ HH.text "Current value:"
, HH.strong_ [ HH.text (show state) ]
]
, HH.button
[ HE.onClick \_ -> Increment ]
[ HH.text ("Increment") ]
]
handleAction :: forall o m. Action -> H.HalogenM State Action () o m Unit
handleAction = case _ of
Increment ->
H.modify_ (_ + 1)
handleQuery :: forall o m a. Query a -> H.HalogenM State Action () o m (Maybe a)
handleQuery = case _ of
GetCount k ->
Just <<< k <$> H.get

@ -1,52 +0,0 @@
module App.ComponentC where
import Prelude
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
type Slot = H.Slot Query Void
data Query a = GetValue (String -> a)
data Action = HandleInput String
type State = String
component :: forall i o m. H.Component Query i o m
component =
H.mkComponent
{ initialState
, render
, eval: H.mkEval $ H.defaultEval
{ handleAction = handleAction
, handleQuery = handleQuery
}
}
initialState :: forall i. i -> State
initialState _ = "Hello"
render :: forall m. State -> H.ComponentHTML Action () m
render state =
HH.label_
[ HH.p_ [ HH.text "What do you have to say?" ]
, HH.input
[ HP.value state
, HE.onValueInput HandleInput
]
]
handleAction :: forall o m. Action -> H.HalogenM State Action () o m Unit
handleAction = case _ of
HandleInput value ->
H.put value
handleQuery :: forall o m a. Query a -> H.HalogenM State Action () o m (Maybe a)
handleQuery = case _ of
GetValue k ->
Just <<< k <$> H.get

@ -3,11 +3,7 @@ module App.Container where
import Prelude
import Data.Maybe (Maybe(..))
import App.ComponentA as CA
import App.ComponentB as CB
import App.ComponentC as CC
import App.AuthenticationForm as AF
import App.OriginalInterface as OI
import Halogen as H
import Halogen.HTML as HH
-- import Halogen.HTML.Events as HE
@ -15,28 +11,16 @@ import Halogen.HTML.Properties as HP
import Type.Proxy (Proxy(..))
import Effect.Aff.Class (class MonadAff)
data Action = ReadStates | Authenticated AF.Output
data Action
= Authenticated AF.Output -- User has been authenticated.
type State =
{ a :: Maybe Boolean
, b :: Maybe Int
, c :: Maybe String
, token :: Maybe String
}
type State = { token :: Maybe String }
type ChildSlots =
( a :: CA.Slot Unit
, b :: CB.Slot Unit
, c :: CC.Slot Unit
, af :: AF.Slot Unit
, oi :: OI.Slot Unit
( af :: AF.Slot Unit
)
_a = Proxy :: Proxy "a"
_b = Proxy :: Proxy "b"
_c = Proxy :: Proxy "c"
_af = Proxy :: Proxy "af"
_oi = Proxy :: Proxy "oi"
component :: forall q i o m. MonadAff m => H.Component q i o m
component =
@ -47,15 +31,13 @@ component =
}
initialState :: forall i. i -> State
initialState _ = { a: Nothing, b: Nothing, c: Nothing, token: Nothing }
initialState _ = { token: Nothing }
render :: forall m. MonadAff m => State -> H.ComponentHTML Action ChildSlots m
render state
= HH.div_ $
[ render_auth_form
, div_token
--, render_original_interface
--, useless_stuff
]
where
div_token :: forall monad. MonadAff monad => H.ComponentHTML Action ChildSlots monad
@ -75,50 +57,7 @@ render state
[ HP.class_ (H.ClassName "box") ]
[ HH.p_ [ HH.text ("Token is: " <> current_token) ] ]
--render_original_interface :: forall monad. MonadAff monad => H.ComponentHTML Action ChildSlots monad
--render_original_interface =
-- HH.div
-- [ HP.class_ (H.ClassName "box") ]
-- [ HH.h1_ [ HH.text "Original interface" ]
-- , HH.slot_ _oi unit OI.component "ws://127.0.0.1:8080"
-- ]
-- useless_stuff :: forall monad. MonadAff monad => H.ComponentHTML Action ChildSlots monad
-- useless_stuff =
-- HH.div_ [
-- HH.div
-- [ HP.class_ (H.ClassName "box") ]
-- [ HH.h1_ [ HH.text "Component A" ]
-- , HH.slot_ _a unit CA.component unit
-- ]
-- , HH.div
-- [ HP.class_ (H.ClassName "box") ]
-- [ HH.h1_ [ HH.text "Component B" ]
-- , HH.slot_ _b unit CB.component unit
-- ]
-- , HH.div
-- [ HP.class_ (H.ClassName "box") ]
-- [ HH.h1_ [ HH.text "Component C" ]
-- , HH.slot_ _c unit CC.component unit
-- ]
-- , HH.p_
-- [ HH.text "Last observed states:" ]
-- , HH.ul_
-- [ HH.li_ [ HH.text ("Component A: " <> show state.a) ]
-- , HH.li_ [ HH.text ("Component B: " <> show state.b) ]
-- , HH.li_ [ HH.text ("Component C: " <> show state.c) ]
-- ]
-- , HH.button
-- [ HE.onClick \_ -> ReadStates ]
-- [ HH.text "Check states now" ]
-- ]
handleAction :: forall o monad. MonadAff monad => Action -> H.HalogenM State Action ChildSlots o monad Unit
handleAction = case _ of
Authenticated (AF.AuthToken newtoken) -> H.modify_ _ { token = Just newtoken }
ReadStates -> do
{ token } <- H.get
a <- H.request _a unit CA.IsOn
b <- H.request _b unit CB.GetCount
c <- H.request _c unit CC.GetValue
H.put { a, b, c, token }

Loading…
Cancel
Save