ittyon.core
An in-memory immutable database designed to manage game state.
-index
(-index state transition)
An intention to update the supplied index with a transition. Expected to return a function that updates the index. Dispatches off the transition op and the aspect. Composes the returned functions.
-react
(-react state transition)
An intention that returns an ordered collection of reaction transitions, given a state and a valid transition that is going to be applied to that state. Dispatches off the transition op and the aspect. Concatenates the results of inherited keys.
-valid?
(-valid? state transition)
An intention to determine whether a transition is valid for a particular state. Dispatches off the transition op and the aspect. Combines results of inherited keys with logical AND.
commit
(commit state transition)
(commit state transition xform)
Takes a state and a transition, and if the transition is valid, returns a new state with the transition and any reactions applied. If the transition is not valid for the state, an ExceptionInfo is thrown with the failing transition and state as keys. A transducer for transforming the reactions of the transition may be supplied as an optional third argument.
derive
(derive h? tag & parents)
Operates the same as clojure.core/derive, except that multiple parent arguments may be specified.
index
(index state transition)
Update the state’s indexes for a single transition. Extend using the -index intention.
periodically
(periodically freq func)
Periodically evaluate a zero-argument function a specified number of times a second.
react
(react state transition)
Return a seq of reaction transitions, or nil, for a given state and transition. Extend using the -react intention.
state
(state)
(state facts)
Return a new state, either empty or prepopulated with a collection of facts.
tick
(tick state time)
Update a state by moving the clock forward to a new time. This may generate reactions that alter the state.
transact
(transact state transitions)
(transact state transitions xform)
Takes a state and an ordered collection of transitions, and returns a new state with the transitions committed in order. Also adds a :last-transact
key to the resulting state that contains the committed transitions. If any of the transitions fail, an ExceptionInfo is thrown. A transducer for transforming the reactions of each transition may be supplied as an optional third argument.
transition?
(transition? x)
Return true if x is a transition. A transition is a vector of five values: operation, entity, aspect, value and time. These are commonly abbreviated to [o e a v t]
. The operation, o, is either :assert
or :revoke
. The aspect, a, must be a keyword.
update
(update state transition)
Update a state with a single transition and return the new state. Combines update-snapshot with index.
update-snapshot
(update-snapshot {n :count, :as state} [o e a v t])
Update the state’s snapshot for a single transition.
valid?
(valid? state transition)
Return true if the transition is a valid transition for the given state. Extend using the -valid? intention.