- data PushIO
- interpret :: Typeable a => (Event PushIO a -> Event PushIO b) -> [a] -> IO [[b]]
- data NetworkDescription a
- compile :: NetworkDescription () -> IO EventNetwork
- type AddHandler a = (a -> IO ()) -> IO (IO ())
- fromAddHandler :: Typeable a => AddHandler a -> NetworkDescription (Event PushIO a)
- reactimate :: Event PushIO (IO ()) -> NetworkDescription ()
- liftIO :: MonadIO m => forall a. IO a -> m a
- data EventNetwork
- run :: EventNetwork -> IO ()
- pause :: EventNetwork -> IO ()
- newAddHandler :: IO (AddHandler a, a -> IO ())
- module Data.Dynamic
Build event networks using existing event-based frameworks and run them.
Simple way to run an event graph. Very useful for testing.
Building event networks with input and output
After having read all about
you want to hook them up to an existing event-based framework,
How do you do that?
This Reactive.Banana.Implementation module allows you to obtain input events from external sources and it allows you perform output in reaction to events.
In constrast, the functions from Reactive.Banana.Model allow you to express the output events in terms of the input events. This expression is called an event graph.
An event network is an event graph together with inputs and outputs.
To build an event network,
describe the inputs, outputs and event graph in the
and use the
compile function to obtain an event network from that.
To run an event network, use the
The network will register its input event handlers and start producing output.
A typical setup looks like this:
main = do -- initialize your GUI framework window <- newWindow ... -- build the event network network <- compile $ do -- input: obtain Event from functions that register event handlers emouse <- fromAddHandler (registerMouseEvent window) ekeyboard <- fromAddHandler (registerKeyEvent window) -- express event graph let behavior1 = accumB ... ... event15 = union event13 event14 -- output: animate some event occurences reactimate $ fmap print event15 reactimate $ fmap drawCircle eventCircle -- register handlers and start producing outputs run network
In short, you use
fromAddHandler to obtain input events.
The library uses this to register event handlers
with your event-based framework.
To animate output events, use the
Monad for describing event networks.
Note: It is forbidden to smuggle values of types
NetworkDescription monad. This shouldn't be possible by default,
but you might get clever and use
IORef to circumvent this.
Don't do that, it won't work and also has a 99,98% chance of
destroying the earth by summoning time-traveling zygohistomorphisms.
A value of type
AddHandler a is just a facility for registering
callback functions, also known as event handlers.
The type is a bit mysterious, it works like this:
do unregisterMyHandler <- addHandler myHandler
The argument is an event handler that will be registered. The return value is an action that unregisters this very event handler again.
Event from an
When the event network is run, this will register a callback function such that an event will occur whenever the callback function is called.
IO action whenever the event occurs.
Running event networks
Data type that represents a compiled event network. It may be paused or already running.
Run an event network. The inputs will register their event handlers, so that the networks starts to produce outputs in response to input events.
Pause an event network. Immediately stop producing output and unregister all event handlers for inputs. Hence, the network stops responding to input events, but it's state will be preserved.
You can resume the network with
Note: You can stop a network even while it is processing events,
i.e. you can use
pause as an argument to
The network will not stop immediately though, only after
the current event has been processed completely.
Build a facility to register and unregister event handlers.
This function is only useful if you want to hook up this library to a poorly designed event-based framework, or roll your own.