packages feed

snaplet-acid-state 0.1 → 0.2

raw patch · 2 files changed

+57/−23 lines, 2 filesdep ~snapPVP ok

version bump matches the API change (PVP)

Dependency ranges changed: snap

API changes (from Hackage documentation)

+ Snap.Snaplet.AcidState: getAcidState :: (HasAcid s st, MonadSnaplet m, MonadState s (m b b)) => m b v (AcidState st)
- Snap.Snaplet.AcidState: class HasAcid myState acidState
+ Snap.Snaplet.AcidState: class HasAcid myState acidState | myState -> acidState
- Snap.Snaplet.AcidState: closeAcidState :: (MonadIO m, MonadState s m, HasAcid s st) => m ()
+ Snap.Snaplet.AcidState: closeAcidState :: (MonadIO (m b v), MonadSnaplet m, MonadState s (m b b), HasAcid s st) => m b v ()
- Snap.Snaplet.AcidState: createCheckpoint :: (MonadIO m, MonadState s m, HasAcid s st) => m ()
+ Snap.Snaplet.AcidState: createCheckpoint :: (MonadIO (m b v), MonadSnaplet m, MonadState s (m b b), HasAcid s st) => m b v ()
- Snap.Snaplet.AcidState: query :: (HasAcid s (MethodState event), MonadIO m, QueryEvent event, MonadState s m) => event -> m (EventResult event)
+ Snap.Snaplet.AcidState: query :: (HasAcid s (MethodState event), MonadSnaplet m, MonadState s (m b b), QueryEvent event, MonadIO (m b v)) => event -> m b v (EventResult event)
- Snap.Snaplet.AcidState: update :: (MonadState s m, HasAcid s (MethodState event), UpdateEvent event, MonadIO m) => event -> m (EventResult event)
+ Snap.Snaplet.AcidState: update :: (HasAcid s (MethodState event), MonadSnaplet m, MonadState s (m b b), UpdateEvent event, MonadIO (m b v)) => event -> m b v (EventResult event)

Files

snaplet-acid-state.cabal view
@@ -1,7 +1,7 @@ name:           snaplet-acid-state-version:        0.1+version:        0.2 synopsis:       acid-state snaplet for Snap Framework-description:    This snaplet that makes it easy to use acid-state in a Snap+description:    This snaplet makes it easy to use acid-state in a Snap                 application. license:        BSD3 license-file:   LICENSE@@ -9,7 +9,8 @@ maintainer:     mightybyte@gmail.com build-type:     Simple cabal-version:  >= 1.6-category:       Web+homepage:       https://github.com/mightybyte/snaplet-acid-state+category:       Web, Snap  extra-source-files:  LICENSE @@ -26,7 +27,7 @@   build-depends:     acid-state                >= 0.6     && < 0.7,     base                      >= 4       && < 5,-    snap                      >= 0.6     && < 0.8,+    snap                      >= 0.6     && < 0.9,     text                      >= 0.11    && < 0.12    ghc-options: -Wall -fwarn-tabs -funbox-strict-fields
src/Snap/Snaplet/AcidState.hs view
@@ -6,11 +6,13 @@ {-# LANGUAGE NoMonomorphismRestriction #-} {-# LANGUAGE OverloadedStrings         #-} {-# LANGUAGE RankNTypes                #-}+{-# LANGUAGE ScopedTypeVariables       #-} module Snap.Snaplet.AcidState   ( Acid   , HasAcid(..)   , acidInit   , acidInit'+  , getAcidState   , update   , query   , createCheckpoint@@ -19,6 +21,9 @@   , module Data.Acid   ) where ++import           Prelude hiding ((.), id)+import           Control.Category import qualified Data.Acid as A import qualified Data.Acid.Advanced as A import           Data.Acid hiding (update@@ -39,7 +44,7 @@  ------------------------------------------------------------------------------ -- | Data type holding acid-state snaplet data.-data Acid st = Acid+newtype Acid st = Acid     { _acidStore :: A.AcidState st     } @@ -51,9 +56,8 @@          => st          -- ^ Initial state to be used if           -> SnapletInit b (Acid st)-acidInit initial = makeSnaplet "acid-state" description Nothing $ do-    st <- liftIO $ A.openLocalState initial-    return $ Acid st+acidInit initial = makeSnaplet "acid-state" description Nothing $+    initWorker (A.openLocalState initial)   ------------------------------------------------------------------------------@@ -64,8 +68,16 @@           -> st           -- ^ Initial state to be used if            -> SnapletInit b (Acid st)-acidInit' location initial = makeSnaplet "acid-state" description Nothing $ do-    st <- liftIO $ A.openLocalStateFrom location initial+acidInit' location initial = makeSnaplet "acid-state" description Nothing $+    initWorker (A.openLocalStateFrom location initial)+++------------------------------------------------------------------------------+-- | Core init functionality common to both exported variants.+initWorker :: IO (AcidState st) -> Initializer b v (Acid st)+initWorker f = do+    st <- liftIO f+    onUnload (A.closeAcidState st)     return $ Acid st  @@ -78,7 +90,7 @@ -- > data App = App { ... _acid :: Snaplet (Acid MyState) ... } -- > instance HasAcid App MyState where -- >     getAcidStore = getL (snapletValue . acid)-class HasAcid myState acidState where+class HasAcid myState acidState | myState -> acidState where     getAcidStore :: myState -> (Acid acidState)  @@ -86,18 +98,24 @@     getAcidStore = id  -getAcidState :: forall a st. HasAcid a st => a -> AcidState st-getAcidState = _acidStore . getAcidStore+------------------------------------------------------------------------------+-- | Lower-level function providing direct access to the AcidState data type.+getAcidState :: (HasAcid s st, MonadSnaplet m, MonadState s (m b b))+    => m b v (AcidState st)+getAcidState = withTop' id $ gets $ _acidStore . getAcidStore   ------------------------------------------------------------------------------ -- | Wrapper for acid-state's update function that works for arbitrary -- instances of HasAcid.-update :: (MonadState s m, HasAcid s (A.MethodState event),-           UpdateEvent event, MonadIO m)-       => event -> m (EventResult event)+update :: (HasAcid s (A.MethodState event),+           MonadSnaplet m,+           MonadState s (m b b),+           UpdateEvent event,+           MonadIO (m b v))+       => event -> m b v (EventResult event) update event = do-    st <- gets getAcidState+    st <- getAcidState     liftIO $ A.update st event  @@ -105,25 +123,40 @@ -- | Wrapper for acid-state's query function that works for arbitrary -- instances of HasAcid. query :: (HasAcid s (A.MethodState event),-          MonadIO m, QueryEvent event, MonadState s m)-      => event -> m (EventResult event)+          MonadSnaplet m,+          MonadState s (m b b),+          QueryEvent event,+          MonadIO (m b v))+      => event -> m b v (EventResult event) query event = do-    st <- gets getAcidState+    st <- getAcidState     liftIO $ A.query st event   ------------------------------------------------------------------------------ -- | Wrapper for acid-state's createCheckpoint function that works for -- arbitrary instances of HasAcid.+createCheckpoint :: (MonadIO (m b v),+                     MonadSnaplet m,+                     MonadState s (m b b),+                     HasAcid s st)+                 => m b v () createCheckpoint = do-    st <- gets getAcidState+    st <- getAcidState     liftIO $ A.createCheckpoint st   ------------------------------------------------------------------------------ -- | Wrapper for acid-state's closeAcidState function that works for--- arbitrary instances of HasAcid.+-- arbitrary instances of HasAcid.  The state is automatically closed by the+-- snaplet's unload action, but this is here in case the user needs more+-- control.+closeAcidState :: (MonadIO (m b v),+                   MonadSnaplet m,+                   MonadState s (m b b),+                   HasAcid s st)+               => m b v () closeAcidState = do-    st <- gets getAcidState+    st <- getAcidState     liftIO $ A.closeAcidState st