on 52182bc help sign in
project-m36/src/lib/ProjectM36/Notifications.hs
17 lines 958 B history raw
1module ProjectM36.Notifications where
2import ProjectM36.Base
3import ProjectM36.RelationalExpression
4import Control.Monad.Trans.Reader
5import qualified Data.Map as M
6import Data.Either (isRight)
8-- | Returns the notifications which should be triggered based on the transition from the first 'DatabaseContext' to the second 'DatabaseContext'.
9notificationChanges :: Notifications -> DatabaseContext -> DatabaseContext -> Notifications
10notificationChanges nots context1 context2 = M.filter notificationFilter nots
11 where
12 notificationFilter (Notification chExpr _ _) = let oldChangeEval = evalChangeExpr chExpr (RelationalExprStateElems context1)
13 newChangeEval = evalChangeExpr chExpr (RelationalExprStateElems context2) in
14 oldChangeEval /= newChangeEval && isRight oldChangeEval
15 evalChangeExpr chExpr = runReader (evalRelationalExpr chExpr)