Tree

abstract class Tree<T : TreeState<*, *, *, *, *>, C : Create<*>, U : Update<*>, D : Delete<*>, M : Move<*>>(state: T)

A reusable aggregate of one tree, such as a tenant's categories or departments: subclass it with the concrete commands, annotate the subclass @AggregateRoot, and the compiler binds the command functions declared here, with the type arguments the subclass gives (its state T, and its commands C, U, D and M):

@AggregateRoot
class Category(state: CategoryState) :
Tree<CategoryState, CreateCategory, UpdateCategory, DeleteCategory, MoveCategory>(state) {
override fun maxLevel(): Int = 3
}

A command that breaks a rule of the tree is rejected with a TreeRejections code, its message from the overridable ...ErrorMessage functions. The verify... hooks run after the tree's own rules and may reject too, after I/O if they need it (they suspend). Creating a node answers the caller with the node's code under the result key code (DecideScope.putResult).

Constructors

Link copied to clipboard
constructor(state: T)

Functions

Link copied to clipboard
open suspend fun onCreate(command: C, scope: DecideScope): Decision

Creates a node under its parent, after its siblings, with a generated code (generateCode); the parent must exist and the node must not be deeper than maxLevel.

Link copied to clipboard
open suspend fun onDelete(command: D, scope: DecideScope): Decision

Deletes an existing node without children.

Link copied to clipboard
open fun onMove(command: M): Decision

Orders sibling nodes: each code must be of an existing node, given once, and all of them of one parent.

Link copied to clipboard
open suspend fun onUpdate(command: U, scope: DecideScope): Decision

Updates an existing node.