| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Eventium.CommandHandler
Description
Defines a Command Handler type.
Synopsis
- data CommandHandler state event command = CommandHandler {
- commandHandlerHandler :: state -> command -> [event]
- commandHandlerProjection :: Projection state event
- allCommandHandlerStates :: CommandHandler state event command -> [command] -> [state]
- applyCommandHandler :: Monad m => VersionedEventStoreWriter m event -> VersionedEventStoreReader m event -> CommandHandler state event command -> UUID -> command -> m [event]
- serializedCommandHandler :: CommandHandler state event command -> Serializer event serializedEvent -> Serializer command serializedCommand -> CommandHandler state serializedEvent serializedCommand
Documentation
data CommandHandler state event command Source #
An CommandHandler is a combination of a Projection and a function to
validate commands against that Projection. When using a command handler in
some service, it is common to simply load the latest projection state from
the event store and handle the command. If the command is valid then the new
events are applied to the projection in the event store.
Constructors
| CommandHandler | |
Fields
| |
allCommandHandlerStates :: CommandHandler state event command -> [command] -> [state] Source #
Given a list commands, produce all of the states the command handler's
projection sees. This is useful for unit testing a CommandHandler.
applyCommandHandler :: Monad m => VersionedEventStoreWriter m event -> VersionedEventStoreReader m event -> CommandHandler state event command -> UUID -> command -> m [event] Source #
Loads the latest version of a Projection from the event store and tries to
apply the CommandHandler command to it. If the command succeeds, then this
saves the events back to the store as well.
serializedCommandHandler :: CommandHandler state event command -> Serializer event serializedEvent -> Serializer command serializedCommand -> CommandHandler state serializedEvent serializedCommand Source #
Use a pair of Serializers to wrap a CommandHandler with event type event
and command type command so it uses the serializedEvent and
serializedCommand types.