front 0.0.0.3 → 0.0.0.4
raw patch · 3 files changed
+16/−20 lines, 3 filesdep ~blaze-htmldep ~blaze-markupdep ~bytestringPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
Dependency ranges changed: blaze-html, blaze-markup, bytestring, fay, text
API changes (from Hackage documentation)
- Web.Front.Broadcast: class Data cmd => CommandHandler cache model cmd
- Web.Front.Broadcast: onCommand :: CommandHandler cache model cmd => Value -> cache model -> ClientId -> IO (Out (Action cmd))
- Web.Front.Broadcast: interact :: (CommandHandler cache model message, Data message, Data message2) => Connection -> TChan (Out (Action message)) -> TChan (Out message2) -> cache model -> ClientId -> IO ()
+ Web.Front.Broadcast: interact :: (Data message, Data message2) => (Value -> cache model -> ClientId -> IO (Out (Action message))) -> Connection -> TChan (Out (Action message)) -> TChan (Out message2) -> cache model -> ClientId -> IO ()
Files
- ChangeLog.md +5/−0
- front.cabal +6/−6
- src/Web/Front/Broadcast.hs +5/−14
ChangeLog.md view
@@ -1,5 +1,10 @@ # Revision history for front +## 0.0.0.4 -- 2020-03-15++* Support GHC 8.6.5, switch to LTS-14.+* Change `CommandHandler` typeclass to higher-order function.+ ## 0.0.0.3 -- 2020-02-04 * `Todo` example reworked to be complaint with http://todomvc.com.
front.cabal view
@@ -2,7 +2,7 @@ -- see http://haskell.org/cabal/users-guide/ name: front-version: 0.0.0.3+version: 0.0.0.4 synopsis: A reactive frontend web framework description: A reactive frontend web framework. See haskell-front.org for more details. homepage: haskell-front.org@@ -40,12 +40,12 @@ , async , stm , conduit- , text >=1.2 && <1.3+ , text >=1.2 , mtl- , bytestring >=0.10 && <0.11- , blaze-markup >=0.8 && <0.10- , blaze-html >=0.9 && <0.10- , fay >= 0.24.0.2+ , bytestring >=0.10 + , blaze-markup >=0.8+ , blaze-html >=0.9 + , fay >= 0.24.0.5 , fay-dom , fay-websockets , websockets
src/Web/Front/Broadcast.hs view
@@ -1,4 +1,4 @@-{-# LANGUAGE MultiParamTypeClasses #-}+{-# LANGUAGE RankNTypes #-} module Web.Front.Broadcast where import Bridge@@ -20,14 +20,15 @@ -- First one is responsible for reading data from stream, decoding JSON message, executing custom business logic implemented by user and pushing the produced outgoing 'message' to 'TChan'. -- The second process is constantly reading from 'TChan', encoding the given message and pushing it to all subscribers. interact- :: (CommandHandler cache model message, Data message, Data message2)- => Connection+ :: (Data message, Data message2)+ => (Value -> cache model -> ClientId -> IO (Out (Action message)))+ -> Connection -> TChan (Out (Action message)) -> TChan (Out message2) -> cache model -> ClientId -> IO ()-interact stream in' out' tvar client = do+interact onCommand stream in' out' tvar client = do race_ (readLoop stream in' tvar client) (writeLoop stream out' client)@@ -53,10 +54,6 @@ ExecuteClient cid task ExecuteAll sendTextData _stream (toLazyText $ encodeToTextBuilder json2) - readLoop- :: (CommandHandler cache model message, Data message)- => Connection -> TChan (Out (Action message))- -> cache model -> ClientId -> IO () readLoop _stream _in _tvar _client = forever $ liftIO $ do data' <- receiveData _stream runConduit $ yield data' .| mapM_C (\cmdstr -> do@@ -66,9 +63,3 @@ liftIO $ putStrLn $ show cmd res <- onCommand cmd _tvar _client atomically $ writeTChan _in res)---- | 'CommandHandler' class contains all business logic, i.e. how to change the given state ('cache model'), synchronize state for all online sessions and produce outgoing message with the 'Action'. 'Action' contains 'ClientId' to separate different sessions, 'ExecuteStrategy' to tell the 'Client' how to handle incoming message.-class Data cmd => CommandHandler cache model cmd where- onCommand- :: Value -> cache model -> ClientId -> IO (Out (Action cmd))-