From 5c0763be32216915def4d96af6434fc562f2c0b0 Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar Date: Mon, 17 May 2021 19:20:40 -0400 Subject: [PATCH] Allow passing initial value to mount --- src/Ema/Helper/FileSystem.hs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Ema/Helper/FileSystem.hs b/src/Ema/Helper/FileSystem.hs index d149230..cb050b5 100644 --- a/src/Ema/Helper/FileSystem.hs +++ b/src/Ema/Helper/FileSystem.hs @@ -48,7 +48,6 @@ mountOnLVar :: ( MonadIO m, MonadUnliftIO m, MonadLogger m, - Default model, Show b, Ord b ) => @@ -57,7 +56,12 @@ mountOnLVar :: -- | Only include these files (exclude everything else) [(b, FilePattern)] -> -- | The `LVar` onto which to mount. + -- + -- NOTE: It must not be set already. Otherwise, the value will be overriden + -- with the initial value argument (next). LVar model -> + -- | Initial value of model, onto which to apply updates. + model -> -- | How to update the model given a file action. -- -- `b` is the tag associated with the `FilePattern` that selected this @@ -68,13 +72,13 @@ mountOnLVar :: -- If the action throws an exception, it will be logged and ignored. ([(b, [FilePath])] -> FileAction -> m (model -> model)) -> m () -mountOnLVar folder pats var toAction' = do +mountOnLVar folder pats var var0 toAction' = do let toAction x = interceptExceptions id . toAction' x log LevelInfo $ "Mounting path " <> toText folder <> " (filter: " <> show pats <> ") onto LVar" LVar.set var =<< do fs <- filesMatchingWithTag folder pats initialAction <- toAction fs Update - pure $ initialAction def + pure $ initialAction var0 onChange folder $ \fp change -> do whenJust (getTag pats fp) $ \tag -> do -- TODO: We should probably debounce and group frequently-firing events