# `Datumo.StateChange`
[🔗](https://github.com/ortegacmanuel/datumo/blob/v0.1.0/lib/datumo/state_change.ex#L1)

Behaviour for write slices (the Decider pattern with DCB).

Pick from history, fold into current state, execute the command → new events
or a rejection.

## DCB append conditions

`query/1` defines which events to read (SourcingCriteria).
`append_condition/1` defines which concurrent events would invalidate the
decision (AppendCriteria).

`next_query/1` (optional) is what else to read, given what's folded so far:
the plots of a lot's receptions can't be named before the lot is read.
`Datumo.Decide` reads only the new ones and stops when none are new; every
follow-up query joins the append condition.

By default `append_condition/1` falls back to `query/1` — symmetric, which is
the safe value. Override it when concurrent events can only strengthen your
invariant and shouldn't cause a conflict (the asymmetric DCB pattern).

# `append_condition`

```elixir
@callback append_condition(command :: term()) :: term()
```

# `apply_event`

```elixir
@callback apply_event(state :: term(), event :: map()) :: term()
```

# `execute`

```elixir
@callback execute(command :: term(), state :: term()) ::
  {:ok, [term()]} | {:error, term()}
```

# `initial_state`

```elixir
@callback initial_state() :: term()
```

# `next_query`
*optional* 

```elixir
@callback next_query(state :: term()) :: term() | nil
```

# `query`

```elixir
@callback query(command :: term()) :: term()
```

---

*Consult [api-reference.md](api-reference.md) for complete listing*
