View Source Backstage.Aggregate protocol (backstage v0.0.2)

An entity used to enforce business rules and ensure consistent state.

When implementing an Aggregate, consider what rules are important to the business for the given entity. For example, this is where you may enforce email uniqueness or age restrictions for users if it is important to your business.

Summary

Types

t()

All the types that implement this protocol.

Functions

Validates the incoming command meets business requirements, if any.

Modifies Aggregate state based on some or all data from the event.

Types

@type aggregate() :: struct()
@type event() :: struct()
@type t() :: term()

All the types that implement this protocol.

Functions

Link to this function

handle_command(command, state)

View Source
@spec handle_command(command :: Backstage.Command.t(), state :: term()) ::
  event() | {:error, term()}

Validates the incoming command meets business requirements, if any.

Returns an event struct or an error tuple.

Link to this function

handle_event(event, state)

View Source
@spec handle_event(event :: struct(), state :: term()) :: aggregate()

Modifies Aggregate state based on some or all data from the event.

Returns an updated aggregate struct.