Skip to content

Commit

Permalink
Add a note about why 'ClientState' is bad
Browse files Browse the repository at this point in the history
This is maybe opinionated and I'm happy to discuss this, but I had a
reason of why I implemented it differently before.
  • Loading branch information
ch1bo committed Sep 13, 2021
1 parent c57e2d3 commit 6c3eefb
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions hydra-tui/src/Hydra/TUI.hs
Expand Up @@ -64,6 +64,10 @@ data State = State
, feedback :: Maybe UserFeedback
}

-- XXX(SN): This is what I had tried to avoid in the past.. refactor back into a
-- "make impossible states unrepresentable". Allowing 'Disconnected' + other
-- info we still have around in the 'State' brings us into the uncomfortable
-- situation of needing to decide which of the values are not stale.
data ClientState = Connected | Disconnected

data DialogState where
Expand Down Expand Up @@ -365,9 +369,9 @@ draw s =
tuiVersion = str "Hydra TUI " <+> withAttr info (str (showVersion version))
ownAddress = str "Address " <+> withAttr info (str $ toString $ encodeAddress (getAddress (s ^. meL)))
nodeStatus =
str "Node " <+> case s ^. clientStateL of
Disconnected -> withAttr negative $ str $ show (s ^. meL)
Connected -> withAttr positive $ str $ show (s ^. meL)
case s ^. clientStateL of
Disconnected -> withAttr negative $ str $ "Connecting to " <> show (s ^. meL)
Connected -> withAttr positive $ str $ "Connected to " <> show (s ^. meL)

drawRightPanel =
case s ^? dialogStateL of
Expand Down

0 comments on commit 6c3eefb

Please sign in to comment.