Safe Haskell | None |
---|---|
Language | Haskell2010 |
- dispatchEvent :: forall result eventType. (Monoid result, Typeable eventType, Typeable result) => eventType -> Action result
- addListener :: (Typeable eventType, Typeable result, Monoid result) => (eventType -> Action result) -> Action ListenerId
- addListener_ :: (Typeable eventType, Typeable result, Monoid result) => (eventType -> Action result) -> Action ()
- removeListener :: ListenerId -> Action ()
- dispatchBufEvent :: (Monoid result, Typeable eventType, Typeable result) => eventType -> BufAction result
- addBufListener :: (Typeable eventType, Typeable result, Monoid result) => (eventType -> BufAction result) -> BufAction ListenerId
- addBufListener_ :: (Typeable eventType, Typeable result, Monoid result) => (eventType -> BufAction result) -> BufAction ()
- removeBufListener :: ListenerId -> BufAction ()
- type Dispatcher = forall event. Typeable event => event -> IO ()
- data ListenerId
- onInit :: Action result -> Action ()
- dispatchInit :: Action ()
- afterInit :: Action a -> Action ()
- dispatchAfterInit :: Action ()
- beforeEveryRender :: Action a -> Action ListenerId
- beforeEveryRender_ :: Action a -> Action ()
- dispatchBeforeRender :: Action ()
- beforeEveryEvent :: Action a -> Action ListenerId
- beforeEveryEvent_ :: Action a -> Action ()
- dispatchBeforeEvent :: Action ()
- onEveryRender :: Action a -> Action ListenerId
- onEveryRender_ :: Action a -> Action ()
- dispatchOnRender :: Action ()
- afterEveryRender :: Action a -> Action ListenerId
- afterEveryRender_ :: Action a -> Action ()
- dispatchAfterRender :: Action ()
- onExit :: Action a -> Action ()
- dispatchExit :: Action ()
- onBufAdded :: (BufAdded -> Action result) -> Action ListenerId
- onBufAdded_ :: (BufAdded -> Action result) -> Action ()
- dispatchBufAdded :: BufAdded -> Action ()
- onEveryNewBuffer :: BufAction a -> Action ListenerId
- onEveryNewBuffer_ :: BufAction a -> Action ()
- onBufTextChanged :: (BufTextChanged -> BufAction result) -> BufAction ListenerId
- dispatchBufTextChanged :: BufTextChanged -> BufAction ()
- onKeypress :: (Keypress -> Action result) -> Action ListenerId
- dispatchKeypress :: Keypress -> Action ()
- asyncEventProvider :: (Dispatcher -> IO ()) -> Action ()
- dispatchEventAsync :: Typeable event => IO event -> Action ()
Documentation
dispatchEvent :: forall result eventType. (Monoid result, Typeable eventType, Typeable result) => eventType -> Action result Source #
Dispatches an event of any type. This should be used to define
your own custom event dispatchers (with more concrete types) which you can re-export.
You can collect results from all listeners if they were registered to return an Action result
where result
is a Monoid (for example a list).
addListener :: (Typeable eventType, Typeable result, Monoid result) => (eventType -> Action result) -> Action ListenerId Source #
This adds an event listener which listens for events of eventType
and will run the resulting
Action result
when triggered by some dispatchEvent
.
This should primarily be used to create your own more specific addListener functions which you re-export.
addListener_ :: (Typeable eventType, Typeable result, Monoid result) => (eventType -> Action result) -> Action () Source #
removeListener :: ListenerId -> Action () Source #
Removes the listener represented by the given ListenerId.
dispatchBufEvent :: (Monoid result, Typeable eventType, Typeable result) => eventType -> BufAction result Source #
Dispatches an event of any type to the BufAction's buffer.
See dispatchEvent
addBufListener :: (Typeable eventType, Typeable result, Monoid result) => (eventType -> BufAction result) -> BufAction ListenerId Source #
Adds a listener to the BufAction's buffer.
See addListener
addBufListener_ :: (Typeable eventType, Typeable result, Monoid result) => (eventType -> BufAction result) -> BufAction () Source #
removeBufListener :: ListenerId -> BufAction () Source #
Removes a listener from the BufAction's buffer.
See removeListener
type Dispatcher = forall event. Typeable event => event -> IO () Source #
This is a type alias to make defining your functions for use with asyncEventProvider
easier;
It represents the function your event provider function will be passed to allow dispatching
events. Using this type requires the RankNTypes
language pragma.
data ListenerId Source #
An opaque reverence to a specific registered event-listener.
A ListenerId is used only to remove listeners later with removeListener
.
onInit :: Action result -> Action () Source #
Registers an action to be performed during the Initialization phase.
This phase occurs exactly ONCE when the editor starts up. Though arbitrary actions may be performed in the configuration block; it's recommended to embed such actions in the onInit event listener so that all event listeners are registered before anything Actions occur.
dispatchInit :: Action () Source #
Dispatch the Init
action.
dispatchAfterInit :: Action () Source #
Dispatch the Init
action.
beforeEveryRender :: Action a -> Action ListenerId Source #
Registers an action to be performed BEFORE each render phase.
This is a good spot to add information useful to the renderer since all actions have been performed. Only cosmetic changes should occur during this phase.
beforeEveryRender_ :: Action a -> Action () Source #
dispatchBeforeRender :: Action () Source #
Dispatch the BeforeRender
action.
beforeEveryEvent :: Action a -> Action ListenerId Source #
Registers an action to be performed BEFORE each event phase.
beforeEveryEvent_ :: Action a -> Action () Source #
dispatchBeforeEvent :: Action () Source #
Dispatch the BeforeEvent
action.
onEveryRender :: Action a -> Action ListenerId Source #
Registers an action to be performed during each render phase.
This phase should only be used by extensions which actually render something.
onEveryRender_ :: Action a -> Action () Source #
dispatchOnRender :: Action () Source #
Dispatch the OnRender
action.
afterEveryRender :: Action a -> Action ListenerId Source #
Registers an action to be performed AFTER each render phase.
This is useful for cleaning up extension state that was registered for the renderer, but needs to be cleared before the next iteration.
afterEveryRender_ :: Action a -> Action () Source #
dispatchAfterRender :: Action () Source #
Dispatch the AfterRender
action.
onExit :: Action a -> Action () Source #
Registers an action to be performed during the exit phase.
This is only triggered exactly once when the editor is shutting down. It allows an opportunity to do clean-up, kill any processes you've started, or save any data before the editor terminates.
dispatchExit :: Action () Source #
Dispatch the Exit
action.
onBufAdded :: (BufAdded -> Action result) -> Action ListenerId Source #
Registers an action to be performed after a new buffer is added.
The supplied function will be called with a BufRef
to the new buffer, and the resulting Action
will be run.
onEveryNewBuffer :: BufAction a -> Action ListenerId Source #
Run the given BufAction
over all new buffers
onEveryNewBuffer_ :: BufAction a -> Action () Source #
onBufTextChanged :: (BufTextChanged -> BufAction result) -> BufAction ListenerId Source #
This is fired every time text in a buffer changes.
The range of text which was altered and the new value of that text are provided inside a BufTextChanged
event.
dispatchBufTextChanged :: BufTextChanged -> BufAction () Source #
Dispatch the BufBufTextChanged
action.
onKeypress :: (Keypress -> Action result) -> Action ListenerId Source #
asyncEventProvider :: (Dispatcher -> IO ()) -> Action () Source #
This allows long-running IO processes to provide Events to Rasa asyncronously.
Don't let the type signature confuse you; it's much simpler than it seems.
Let's break it down:
Using the Dispatcher
type with asyncEventProvider requires the RankNTypes
language pragma.
This type as a whole represents a function which accepts a Dispatcher
and returns an IO
;
the dispatcher itself accepts data of ANY Typeable
type and emits it as an event (see Rasa.Internal.Events).
When you call asyncEventProvider
you pass it a function which accepts a dispatch
function as an argument
and then calls it with various events within the resulting IO
.
Note that asyncEventProvider calls forkIO internally, so there's no need to do that yourself.
Here's an example which fires a Timer
event every second.
{-# language RankNTypes #-} data Timer = Timer myTimer :: Dispatcher -> IO () myTimer dispatch = forever $ dispatch Timer >> threadDelay 1000000 myAction :: Action () myAction = onInit $ asyncEventProvider myTimer