(-do-transition fsm
{:keys [_state] :as state}
event
input-event
ignore-unknown-event?)
(-transition-impl fsm state input-event opts)
Return the new state and the actions to execute.
Return the new state and the actions to execute.
(-transition-once fsm
state
event
{:keys [exec debug input-event ignore-unknown-event?]
:or {exec true}})
Do the transition, but would not follow new eventless transitions defined on the target state.
Do the transition, but would not follow new eventless transitions defined on the target state.
(assign f)
Wrap a function into a context assignment function.
Wrap a function into a context assignment function.
(backtrack-ancestors-as-nodes fsm path)
Like backtrack-ancestors-as-paths but resolves the paths into nodes.
Like backtrack-ancestors-as-paths but resolves the paths into nodes.
(backtrack-ancestors-as-paths fsm path)
Return a (maybe lazy) sequence of the node path with all its ancestors, starting from the node and goes up.
Return a (maybe lazy) sequence of the node path with all its ancestors, starting from the node and goes up.
(configuration->_state fsm configuration)
Represent the current configuration in a user-friendly form. It's the reverse
operation of _state->configuration
.
Represent the current configuration in a user-friendly form. It's the reverse operation of `_state->configuration`.
(external-self-transition-actions handler nodes)
Calculate the actions for an external self-transition.
if handler is on [:s1 :s1.1] and current state is [:s1 :s1.1 :s1.1.1] then we shall exit s1.1.1 s1.1 and entry s1.1 s1.1.1 again
if handler is on [:s1] and current state is [:s1 :s1.1 :s1.1.1] then we shall exit s1.1.1 s1.1 s1 and entry s1 s1.1 s1.1.1 again
if handler is on [:s2] and current state is [:s2] then we shall exit s2 and entry s2 again
if handler is on [] and current state is [:s2] then we shall exit s2 Machine and entry Machine s2 again
Calculate the actions for an external self-transition. if handler is on [:s1 :s1.1] and current state is [:s1 :s1.1 :s1.1.1] then we shall exit s1.1.1 s1.1 and entry s1.1 s1.1.1 again if handler is on [:s1] and current state is [:s1 :s1.1 :s1.1.1] then we shall exit s1.1.1 s1.1 s1 and entry s1 s1.1 s1.1.1 again if handler is on [:s2] and current state is [:s2] then we shall exit s2 and entry s2 again if handler is on [] and current state is [:s2] then we shall exit s2 Machine and entry Machine s2 again
(initialize fsm)
(initialize {:keys [initial type] :as fsm}
{:keys [exec debug context] :or {exec true context nil} :as _opts})
(machine orig)
Create a canonical presentation of the machine using malli.
Create a canonical presentation of the machine using malli.
(path->_state xs)
Calculate the _state value based on the node paths.
In our internal code, we need to represent the current state as a series of nodes, but when presenting the current state to the user we need to extract the simplest form.
Calculate the _state value based on the node paths. In our internal code, we need to represent the current state as a series of nodes, but when presenting the current state to the user we need to extract the simplest form.
Schema of an element of a expanded path. We need the transitions/exit/entry information to:
Schema of an element of a expanded path. We need the transitions/exit/entry information to: 1. transitions: in a compound node, decide which level handles the event 2. :id of each level to resolve the target state node. 3. entry/exit: collect the actions during a transtion transition.
(resolve-target base target)
Resolve the given transition target given the current state context.
Rules for resolving the target:
If the target is nil, it's the same as the current state, a.k.a self-transition
If the target is a vector and the first element is :>, it's an absolute path
(f :whatever [:> :s2]) => [:s2]
If the target is a vector and the first element is not :>, it's an relative path
(f [:s1] [:s2]) => :s2 (f [:s1 :s1.1] [:s1.2]) => [:s1 :s1.2]
If the target is a keyword, it's the same as an one-element vector
(f [:s1] :s2) => :s2 (f [:s1 :s1.1] :s1.2) => [:s1 :s1.2]
If the target is a vector and the first element is :., it's a child state of current node:
(f [:s1] [:. :s1.1]) => [:s1 :s1.1]
E.g. given current state [:s1 :s1.1] and a target of :s1.2, it should resolve to [:s1 :s1.2]
Resolve the given transition target given the current state context. Rules for resolving the target: - If the target is nil, it's the same as the current state, a.k.a self-transition - If the target is a vector and the first element is :>, it's an absolute path (f :whatever [:> :s2]) => [:s2] - If the target is a vector and the first element is not :>, it's an relative path (f [:s1] [:s2]) => :s2 (f [:s1 :s1.1] [:s1.2]) => [:s1 :s1.2] - If the target is a keyword, it's the same as an one-element vector (f [:s1] :s2) => :s2 (f [:s1 :s1.1] :s1.2) => [:s1 :s1.2] - If the target is a vector and the first element is :., it's a child state of current node: (f [:s1] [:. :s1.1]) => [:s1 :s1.1] E.g. given current state [:s1 :s1.1] and a target of :s1.2, it should resolve to [:s1 :s1.2]
(select-one-tx fsm
{:keys [path] :as node}
state
{:keys [type] :as event}
input-event)
Given an atomic node and an event, find the first satistifed transition by walking from the node and then its ancestors, until the root.
Return a two-tuple:
Given an atomic node and an event, find the first satistifed transition by walking from the node and then its ancestors, until the root. Return a two-tuple: - The first element is the a boolean indicates whether any transition is found at all (regarding it's satisfied or not) - The second element is the found transition, if any.
Generated internal event for delayed transitions.
Generated internal event for delayed transitions.
See resolve-target
for the synatx of target definition.
See `resolve-target` for the synatx of target definition.
(transition fsm state event)
(transition fsm state event {:as opts :keys [exec debug] :or {exec true}})
Given a machine with its current state, trigger a transition to the next state based on the given event.
The nature and purpose of the transition impl is to get two outputs:
By default it executes all actions, unless the exec
opt is false,
in which case it is a pure function.
Given a machine with its current state, trigger a transition to the next state based on the given event. The nature and purpose of the transition impl is to get two outputs: - the new state - the actions to execute By default it executes all actions, unless the `exec` opt is false, in which case it is a pure function.
(validate-targets root)
(validate-targets root node current-path)
Walk the fsm and try to resolve all transition targets. Raise an exception if any target is invalid.
Walk the fsm and try to resolve all transition targets. Raise an exception if any target is invalid.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close