A data-oriented Clojure library for defining and executing directed acyclic graph's of state machines.
Initially designed as an alternative to component systems such as Integrant, Component or Mount.
(ns app.example
(:require
[org.httpkit.server :as http]))
(def server-component
{:signals {:start (fn start-server [_ {:keys [system port]}]
(http/run-server (create-router system)
{:port port}))
:stop (fn stop-server [server _]
(.close server))}})
(def graph
{:config {:db-path "./data/db"
:http-port 8080}
:db (gx/with-refs [db-name (gx/ref [:config :db-path])]
(jdbc/get-datasource {:dbtype "sqlite"
:dbname db-name}))
:system {:db (gx/ref :db)}
:http/server (gx/component {:system (gx/ref :system)
:port (gx/ref [:config :http-port])}
server-component)})
(comment
(def live-graph
(gx/signal! graph :start))
(gx/signal! live-graph :stop))
A ref can be thought of like a stateless pointer to some other part of the graph - represented as a path.
It can be 'resolved' by calling lookup-in and passing some resolved or partially resolved graph for the ref to use
when looking up its value. This is done internally by gx/values and gx/signal!.
A resolved ref can be derefed using plain old deref or the @ reader macro to obtain its resolved value.
Refs can be inspected to see what their dependencies on other parts of the graph are, which is useful for determining in what order to resolve a graph.
Components are similar to refs in that they can have dependencies on other parts of the graph and are resolved to a
value. Unlike refs however, components are stateful and transition through a lifecycle. This transition happens by
passing signals through the graph which are then processed by components.
Components are made up of input props (which are essentially refs to other values in the graph) and signal handlers.
Component definitions can describe validating functions which will be called as part of executing signals
Can you improve this documentation? These fine people already did:
Alexis Vincent, Artem Medeusheyev, Artem Medeu & Julien VincentEdit on GitHub
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |