web-plugins 0.4.0 → 0.4.1
raw patch · 2 files changed
+31/−1 lines, 2 files
Files
- Web/Plugins/Core.hs +30/−0
- web-plugins.cabal +1/−1
Web/Plugins/Core.hs view
@@ -200,6 +200,7 @@ , putPluginsSt , addPluginState , getPluginState+ , modifyPluginState' , modifyPluginsSt , addHandler , addCleanup@@ -345,6 +346,16 @@ (\p -> do r <- action p ; destroyPlugins OnNormal p; return r) ------------------------------------------------------------------------------+-- PluginsConfig+------------------------------------------------------------------------------++-- | get the current @st@ value from 'Plugins'+getPluginsConfig :: (MonadIO m) => Plugins theme n hook config st+ -> m config+getPluginsConfig (Plugins tps) =+ liftIO $ atomically $ pluginsConfig <$> readTVar tps++------------------------------------------------------------------------------ -- PluginsSt ------------------------------------------------------------------------------ @@ -404,6 +415,25 @@ (Just tvar) -> do dyn <- liftIO $ atomically $ readTVar tvar return $ fromDynamic dyn++-- | modify the plugin state+--+-- If the plugin did not register any state, then this is a noop+modifyPluginState' :: (MonadIO m, Typeable state) =>+ Plugins theme n hook config st+ -> Text -- plugin name+ -> (state -> state)+ -> m ()+modifyPluginState' (Plugins ptv) pluginName modifier =+ do states <- liftIO $ atomically $ pluginsPluginState <$> readTVar ptv+ case Map.lookup pluginName states of+ Nothing -> pure ()+ (Just tvar) ->+ do liftIO $ atomically $ modifyTVar' tvar $ \d ->+ case fromDynamic d of+ Nothing -> d+ (Just st) -> toDyn (modifier st)+ pure () -- | add a new cleanup action to the top of the stack addCleanup :: (MonadIO m) => Plugins theme n hook config st -> When -> IO () -> m ()
web-plugins.cabal view
@@ -1,5 +1,5 @@ name: web-plugins-version: 0.4.0+version: 0.4.1 synopsis: dynamic plugin system for web applications description: This provides a simple framework for defining plugins for a web application. It is designed with the requirement that plugins can be loaded into a running