1 {-# LANGUAGE ScopedTypeVariables, FlexibleContexts #-}
3 module RMCA.Auxiliary.RV where
6 import Data.ReactiveValue
10 newCBMVarRW :: forall a. a -> IO (ReactiveFieldReadWrite IO a)
14 getter = readCBMVar mvar
16 setter = writeCBMVar mvar
17 notifier :: IO () -> IO ()
18 notifier = installCallbackCBMVar mvar
19 return $ ReactiveFieldReadWrite setter getter notifier
21 emptyRW :: (Monoid b, ReactiveValueReadWrite a b m) => a -> m b
23 val <- reactiveValueRead rv
24 reactiveValueWrite rv mempty
27 emptyW :: (Monoid b, ReactiveValueWrite a b m) => a -> m ()
28 emptyW rv = reactiveValueWrite rv mempty
30 (^:>) :: (ReactiveValueRead a b m, ReactiveValueReadWrite c d m) =>
32 notif ^:> rv = reactiveValueOnCanRead notif resync
33 where resync = reactiveValueRead rv >>= reactiveValueWrite rv
35 -- Update when the value is an Event. It would be nice to have that
36 -- even for Maybe as well.
37 (>:>) :: (ReactiveValueRead a (Event b) m, ReactiveValueWrite c b m) =>
39 eventRV >:> rv = reactiveValueOnCanRead eventRV syncOnEvent
40 where syncOnEvent = do
41 erv <- reactiveValueRead eventRV
42 when (isEvent erv) $ reactiveValueWrite rv $ fromEvent erv