packages feed

global-config 0.1.0 → 0.2.0

raw patch · 3 files changed

+14/−7 lines, 3 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ Data.Global.Config: onSetConfig :: GlobalConfig a => a -> IO ()
- Data.Global.Config: class (Default a, Typeable a) => GlobalConfig a where setConfig e = stubConfig `writeIORef` e getConfig = readIORef stubConfig stubConfig = declareIORef "" def
+ Data.Global.Config: class (Default a, Typeable a) => GlobalConfig a where setConfig e = do { stubConfig `writeIORef` e; onSetConfig e } getConfig = readIORef stubConfig stubConfig = declareIORef "" def

Files

global-config.cabal view
@@ -1,5 +1,5 @@ name:           global-config
-version:        0.1.0
+version:        0.2.0
 cabal-version:  >= 1.8
 build-type:     Simple
 author:         Alexander Dorofeev <aka.spin@gmail.com>spin
src/Data/Global/Config.hs view
@@ -20,23 +20,24 @@ -- > instance Default Config
 -- >    def = Config 0 False
 -- > 
--- > instance GlobalConfig Config
--- > 
+-- > instance GlobalConfig Config where
+-- >    onSetConfig = print
+-- >    
 -- > main :: IO ()
 -- > main = do
 -- >    -- try to read unitialized config
 -- >    c1 <- getConfig 
--- >    print (c1 :: Config)
 -- >    -- Config {configInt=0, configBool=False}
 -- >    
 -- >    -- set config and read it
 -- >    setConfig $ Config 1 True
+-- >    -- Config {configInt=1, configBool=True}
 -- >    c2 <- getConfig
 -- >    print (c1 :: Config)
 -- >    -- Config {configInt=1, configBool=True}
 
 module Data.Global.Config (
-    GlobalConfig (setConfig, getConfig)
+    GlobalConfig (setConfig, onSetConfig, getConfig)
 ) where
 
 import Data.Typeable (Typeable)
@@ -48,7 +49,12 @@ class (Default a, Typeable a) => GlobalConfig a where
     -- | Init global config
     setConfig :: a -> IO ()
-    setConfig e = stubConfig `writeIORef` e 
+    setConfig e = do
+        stubConfig `writeIORef` e
+        onSetConfig e 
+    
+    -- | Set config handler
+    onSetConfig :: a -> IO ()
     
     -- | Get global config
     getConfig :: IO a
test/Main.hs view
@@ -55,7 +55,8 @@ instance Default Config where
     def = Config 0 ""
     
-instance GlobalConfig Config
+instance GlobalConfig Config where
+    onSetConfig = print