precept.core
action-ch
apply-additions-to-store
(apply-additions-to-store in)
Reads ops from channel and applies additions to store
apply-changes-to-session
(apply-changes-to-session in)
apply-removals-to-store
(apply-removals-to-store in)
Reads ops from in channel and applies removals to store
batch-complete?
(batch-complete? event batch)
Returns true if the event is fire rules complete or it exists in the batch and the maximum event number received is equal to :total-events
from fire rules complete
ch-chsk
changes-mult
changes-out
changes-xf
(changes-xf f)
chsk
chsk-send!
chsk-state
connect-devtools-socket!
(connect-devtools-socket! options init-cb)
create-change-report-ch
(create-change-report-ch)
(create-change-report-ch f)
Returns core.async channel with operational changes from session. Removes Precept implementation facts when called with no arguments. May be called with a function that will be applied to all :added and :removed facts.
Usage:
(def nil-values-ch
(create-changes-report-ch
(filter (fn [{:keys [e a v t]} record] (nil? v))
%)))
(go-loop []
(let [changes (<! nil-values-ch)]
(println "Facts with nil values added / removed:" changes)))
=> Facts with nil values added / removed: {:added () :removed ()}
create-dto>socket-router
(create-dto>socket-router in send! encoding)
Returns a go-loop that takes from a channel with events emitted by precept.listeners/PersistentSessionEventMessager and calls the provided send function,
intended for use with a precept-devtools socket. Batches events per call to
fire-rules`.
create-fired-session-ch
(create-fired-session-ch)
Returns core.async channel that receives the session after the rules have been fired and before its listener has been replaced.
default-devtools-options
default-group
devtools-socket-ch
devtools-socket-router
dispatch!
(dispatch! f)
done-ch
empty-batch?
(empty-batch? event batch)
groups
handle-event
handle-message
identical-conditions-and-consequences-error
(identical-conditions-and-consequences-error {:keys [existing-name type]})
init-session-ch
init-transactor
(init-transactor)
Parks until session is initialized in (:session precept.state/state) then spawns a transactor that takes from action-ch
.
lens
(lens a path)
matching-conditions-and-consequences
(matching-conditions-and-consequences lhs rhs rules-index)
matching-consequences
(matching-consequences rhs rule-index)
notify!
(notify! sub-name update-fn)
read-changes-from-session
(read-changes-from-session in)
Reads changes from session channel, fires rules, and puts resultant changes on changes channel. Updates session state atom with new session. Changes are returned keyed by :added, :removed as Tuple records.
realized-session
register
(register req)
Should only get called by subscribe
, which determines if a sub exists.
Generates an id used to track requests and responses throughout the system.
req
is a vector of name and params (currently we just support a name). Inserts subscription request into the current session. Responses are generated by subscription handler rules that match request name and insert facts into working memory. Subscriptions are stored in (:subscriptions @state). The lens is a reagent cursor that observes changes to the subscription’s response that is written to the store.
register-rule
multimethod
Returns rule name if found in registry, else registers new rule and returns name
removals-out
resume!
(resume! {:keys [session facts devtools], :as options})
Resets session with provided facts if start!
has been called, otherwise returns the session received as an argument unmodified. Avoids duplicate session creation on page refresh in development when there is stale session metadata in the compiler.
resume-with-devtools!
(resume-with-devtools! options)
session->store
session-mult
start!
(start! {:keys [id session facts devtools], :as options})
Initializes session with facts.
:session
- Instance of clara.rules.engine.LocalSession created byprecept.rules/session
:id
- Value that uniquely identifies the session.:facts
- Vector. Initial facts to be inserted into the session:devtools
(optional) - Boolean or map of options for connecting to a running instance of a Precept devtools server. Default:nil
. Supported devtools options::host
- String with host and port separated by:
. Defaults to default Devtools server address and port0.0.0.0:3232
.:path
- String of path for server socket. Defaults to default Devtools server path/chsk
.:encoding
- Keyword of encoding for devtools socket. One of transit enc-types::json
,:json-verbose
. Defaults to:json-verbose
.
start-with-devtools!
(start-with-devtools! {:keys [session facts devtools], :as options})
subscribe
(subscribe req)
Returns lens that points to a path in the store. Sub is handled by a rule.
swap-session!
(swap-session! next)
swap-session-sync!
(swap-session-sync! next f)
then
(then facts)
Inserts facts into current session
trace
(trace & args)
transactor
(transactor)
Takes from action channel and puts to session->store
channel. Parks until done-ch
returns a message indicating: 1. A transaction of facts (via then
) was inserted into the (global) session ((:session precept.state/state)
) 2. fire-rules
was called on (:session precept.state/state)
3. changes were read from the session and applied to the store
update-session-history
(update-session-history session)
First history entry is most recent