Safe Haskell | Safe |
---|---|

Language | Haskell2010 |

This module holds a reactive program model. It holds a program model, but includes events that other threads can listen to, so that a change in a part of the model is notified to another part of the program. The reactive model is not necessarily concurrent (it doesn't have its own thread), although a facility is included to make it also concurrent (so that event handlers can be called as soon as they are present).

This type includes operations to handle undoing-redoing and tracking which notifications must be triggered in each undo-redo step.

Copyright : (C) Keera Studios Ltd, 2013 License : BSD3 Maintainer : support@keera.co.uk

## Synopsis

- data Event b => ReactiveModel a b c
- class (Eq a, Ord a) => Event a
- emptyRM :: Event b => a -> ReactiveModel a b c
- pendingEvents :: ReactiveModel a b c -> Seq b
- pendingHandlers :: ReactiveModel a b c -> Seq c
- onBasicModel :: Event b => ReactiveModel a b c -> (a -> a) -> ReactiveModel a b c
- onEvent :: Event b => ReactiveModel a b c -> b -> c -> ReactiveModel a b c
- onEvents :: (Foldable container, Event b) => ReactiveModel a b c -> container b -> c -> ReactiveModel a b c
- getPendingHandler :: Event b => ReactiveModel a b c -> (ReactiveModel a b c, Maybe c)
- eventHandlers :: ReactiveModel a b c -> Map b (Seq c)
- prepareEventHandlers :: Event b => ReactiveModel a b c -> ReactiveModel a b c
- triggerEvent :: Event b => ReactiveModel a b c -> b -> ReactiveModel a b c
- triggerEvents :: Event b => ReactiveModel a b c -> Seq b -> ReactiveModel a b c

# Documentation

data Event b => ReactiveModel a b c Source #

A model of kind a with a stack of events of kind b

# Construction

class (Eq a, Ord a) => Event a Source #

A reactive model uses an event datatype with all the events that our model must trigger. An heterogenous container cannot be used because we need an Eq operation that is efficient (a string comparison is not).

Therefore, we can declare operations that require certain events, as long as we create a typeclass for Event types that have a constructor for the kind of events we require.

NOTE: This is experimental code.

emptyRM :: Event b => a -> ReactiveModel a b c Source #

Default constructor (with an empty model, no events and no handlers installed)

# Access

pendingEvents :: ReactiveModel a b c -> Seq b Source #

pendingHandlers :: ReactiveModel a b c -> Seq c Source #

# Modification

onBasicModel :: Event b => ReactiveModel a b c -> (a -> a) -> ReactiveModel a b c Source #

Apply a modification to the internal model (no events are triggered)

onEvent :: Event b => ReactiveModel a b c -> b -> c -> ReactiveModel a b c Source #

Install a handler for an event

onEvents :: (Foldable container, Event b) => ReactiveModel a b c -> container b -> c -> ReactiveModel a b c Source #

getPendingHandler :: Event b => ReactiveModel a b c -> (ReactiveModel a b c, Maybe c) Source #

If any pending handler exists or can be obtained, it is returned and removed from the queue

eventHandlers :: ReactiveModel a b c -> Map b (Seq c) Source #

prepareEventHandlers :: Event b => ReactiveModel a b c -> ReactiveModel a b c Source #

Return a reactive model that has no pending events. All the pending events have been looked up in the eventHandlers table and the handlers have been added to the field pendingHandlers.

triggerEvent :: Event b => ReactiveModel a b c -> b -> ReactiveModel a b c Source #

Trigger an event (execute all handlers associated to it)

triggerEvents :: Event b => ReactiveModel a b c -> Seq b -> ReactiveModel a b c Source #

Trigger many events in sequence (execute all handlers associated to them)