1
1
mirror of https://github.com/srid/ema.git synced 2024-11-29 09:25:14 +03:00

Pass cli action to model runner

This commit is contained in:
Sridhar Ratnakumar 2021-05-25 22:40:56 -04:00
parent 56abc9fc16
commit ccd3649319
3 changed files with 11 additions and 7 deletions

View File

@ -2,6 +2,7 @@
## Unreleased (0.2.0.0)
- TODO(doc) runEma's action gets the `CLI.Action` as argument, to prevent the `gen` command from needing to monitoring files.
- `Asset` type
- Introduce the `Asset` type to distinguishing between static files and generated files. The later can be one of `Html` or `Other`, allowing the live server to handle them sensibly.
- `Ema` typeclass:

View File

@ -39,8 +39,9 @@ runEmaPure ::
(CLI.Action -> LByteString) ->
IO ()
runEmaPure render = do
runEma (\act () () -> AssetGenerated Html $ render act) $ \model -> do
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
@ -55,7 +56,7 @@ runEma ::
(CLI.Action -> model -> route -> Asset LByteString) ->
-- | 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) => LVar model -> m ()) ->
(forall m. (MonadIO m, MonadUnliftIO m, MonadLoggerIO m) => CLI.Action -> LVar model -> m ()) ->
IO ()
runEma render runModel = do
cli <- CLI.cliAction
@ -72,7 +73,7 @@ runEmaWithCli ::
(CLI.Action -> model -> route -> Asset LByteString) ->
-- | 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) => LVar model -> m ()) ->
(forall m. (MonadIO m, MonadUnliftIO m, MonadLoggerIO m) => CLI.Action -> LVar model -> m ()) ->
IO ()
runEmaWithCli cli render runModel = do
model <- LVar.empty
@ -84,7 +85,7 @@ runEmaWithCli cli render runModel = do
logInfoN $ "Launching Ema under: " <> toText cwd
logInfoN "Waiting for initial model ..."
race_
(flip runLoggerLoggingT logger $ runModel model)
(flip runLoggerLoggingT logger $ runModel (CLI.action cli) model)
(flip runLoggerLoggingT logger $ runEmaWithCliInCwd (CLI.action cli) model render)
-- | Run Ema live dev server

View File

@ -21,7 +21,8 @@ generate ::
( MonadIO m,
MonadUnliftIO m,
MonadLoggerIO m,
Ema model route
Ema model route,
HasCallStack
) =>
FilePath ->
model ->
@ -59,7 +60,8 @@ newtype StaticAssetMissing = StaticAssetMissing FilePath
copyDirRecursively ::
( MonadIO m,
MonadUnliftIO m,
MonadLoggerIO m
MonadLoggerIO m,
HasCallStack
) =>
-- | Source file or directory relative to CWD that will be copied
FilePath ->