mirror of
https://github.com/srid/ema.git
synced 2024-11-25 20:12:20 +03:00
Have runEma return Cli
This commit is contained in:
parent
bc0098d94e
commit
0b536ea4d2
@ -5,6 +5,7 @@
|
||||
- Pin TailwindCSS to 2.x, because the 3.x broke our CDN url
|
||||
- Remove unused Cabal deps (#61)
|
||||
- `Tailwind.layoutWith`: don't hardcode `<body>` attrs
|
||||
- `runEma`: return the parsed `Cli`
|
||||
|
||||
## 0.2.0.0 -- 2021-11-21
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
cabal-version: 2.4
|
||||
name: ema
|
||||
version: 0.3.0.1
|
||||
version: 0.3.0.2
|
||||
license: AGPL-3.0-only
|
||||
copyright: 2021 Sridhar Ratnakumar
|
||||
maintainer: srid@srid.ca
|
||||
|
@ -43,10 +43,11 @@ runEmaPure ::
|
||||
(CLI.Action -> LByteString) ->
|
||||
IO ()
|
||||
runEmaPure render = do
|
||||
runEma (\act () () -> AssetGenerated Html $ render act) $ \act model -> do
|
||||
LVar.set model ()
|
||||
when (act == CLI.Run) $ do
|
||||
liftIO $ threadDelay maxBound
|
||||
void $
|
||||
runEma (\act () () -> AssetGenerated Html $ render act) $ \act model -> do
|
||||
LVar.set model ()
|
||||
when (act == CLI.Run) $ do
|
||||
liftIO $ threadDelay maxBound
|
||||
|
||||
-- | Convenient version of @runEmaWith@ that takes initial model and an update
|
||||
-- function. You typically want to use this.
|
||||
@ -61,10 +62,11 @@ runEma ::
|
||||
-- | A long-running IO action that will update the @model@ @LVar@ over time.
|
||||
-- This IO action must set the initial model value in the very beginning.
|
||||
(forall m. (MonadIO m, MonadUnliftIO m, MonadLoggerIO m) => CLI.Action -> LVar model -> m ()) ->
|
||||
IO ()
|
||||
IO Cli
|
||||
runEma render runModel = do
|
||||
cli <- CLI.cliAction
|
||||
runEmaWithCli cli render runModel
|
||||
pure cli
|
||||
|
||||
-- | Like @runEma@ but takes the CLI action
|
||||
--
|
||||
|
@ -33,10 +33,11 @@ instance Ema Model Route where
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
Ema.runEma (\act m -> Ema.AssetGenerated Ema.Html . render act m) $ \act model -> do
|
||||
LVar.set model $ Model "Hello World. "
|
||||
when (act == CLI.Run) $
|
||||
liftIO $ threadDelay maxBound
|
||||
void $
|
||||
Ema.runEma (\act m -> Ema.AssetGenerated Ema.Html . render act m) $ \act model -> do
|
||||
LVar.set model $ Model "Hello World. "
|
||||
when (act == CLI.Run) $
|
||||
liftIO $ threadDelay maxBound
|
||||
|
||||
render :: Ema.CLI.Action -> Model -> Route -> LByteString
|
||||
render emaAction model r =
|
||||
|
@ -37,11 +37,12 @@ instance Ema UTCTime Route where
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
Ema.runEma (\act m -> Ema.AssetGenerated Ema.Html . render act m) $ \_act model ->
|
||||
forever $ do
|
||||
-- logDebugNS "ex:clock" "Refreshing time"
|
||||
LVar.set model =<< liftIO getCurrentTime
|
||||
liftIO $ threadDelay 1000000
|
||||
void $
|
||||
Ema.runEma (\act m -> Ema.AssetGenerated Ema.Html . render act m) $ \_act model ->
|
||||
forever $ do
|
||||
-- logDebugNS "ex:clock" "Refreshing time"
|
||||
LVar.set model =<< liftIO getCurrentTime
|
||||
liftIO $ threadDelay 1000000
|
||||
|
||||
render :: Ema.CLI.Action -> UTCTime -> Route -> LByteString
|
||||
render emaAction now r =
|
||||
|
Loading…
Reference in New Issue
Block a user