From b38ea6a357b73ce33ccb618c36e7fc6607423ca2 Mon Sep 17 00:00:00 2001 From: Jens Nolte <jens@nightmarestudio.de> Date: Fri, 31 Jan 2020 02:58:39 +0100 Subject: [PATCH] Move instances closer to their class --- src/QBar/Core.hs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/QBar/Core.hs b/src/QBar/Core.hs index 5404966..f494e5d 100644 --- a/src/QBar/Core.hs +++ b/src/QBar/Core.hs @@ -58,9 +58,14 @@ type PullBlock = Block PullMode -- |Cached block. Always 'yield's the latest update, so it should only be pulled when the bar is rendered. type CachedBlock = Block CachedMode -class IsBlock a where +class IsCachableBlock a where toCachedBlock :: a -> CachedBlock +instance IsCachableBlock PushBlock where + toCachedBlock = cachePushBlock +instance IsCachableBlock CachedBlock where + toCachedBlock = id + class IsBlockMode a where exitBlock :: Block a instance IsBlockMode PushMode where @@ -78,10 +83,6 @@ data Bar = Bar { newBlockChan :: TChan CachedBlock } -instance IsBlock PushBlock where - toCachedBlock = cachePushBlock -instance IsBlock CachedBlock where - toCachedBlock = id data BarUpdateChannel = BarUpdateChannel (IO ()) type BarUpdateEvent = Event.Event @@ -256,7 +257,7 @@ startPersistentBlockScript path = catchP startScriptProcess handleError updateBlock $ mkBlockOutput . pangoText $ line lift updateBar -addBlock :: IsBlock a => a -> BarIO () +addBlock :: IsCachableBlock a => a -> BarIO () addBlock block = do newBlockChan' <- newBlockChan <$> askBar liftIO $ atomically $ writeTChan newBlockChan' $ toCachedBlock block -- GitLab