mirror of
https://github.com/srid/ema.git
synced 2024-11-25 20:12:20 +03:00
Pass cli action to model runner
This commit is contained in:
parent
56abc9fc16
commit
ccd3649319
@ -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:
|
||||
|
@ -39,9 +39,10 @@ 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 ()
|
||||
liftIO $ threadDelay maxBound
|
||||
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.
|
||||
@ -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
|
||||
|
@ -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 ->
|
||||
|
Loading…
Reference in New Issue
Block a user