Skip to content

Commit

Permalink
Document default Application Log implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
codebeige committed Dec 13, 2023
1 parent 0719539 commit 4ad50f6
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/moira/event.cljs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(ns moira.event
"Implement [[Factory]] for producing Application Events with unique
"Create [[Factory]] for producing Application Events with unique
[[EventId|Event IDs]] and guaranteed ordering based on a
[logical clock](https://en.wikipedia.org/wiki/Logical_clock)."

Expand Down
32 changes: 26 additions & 6 deletions src/moira/log/module.cljs
Original file line number Diff line number Diff line change
@@ -1,24 +1,44 @@
(ns moira.log.module
"Instrument Application Log by setting up
[[moira.log.event-emitter/EventEmitter|EventEmitter]] as a module."

(:require [clojure.spec.alpha :as s]
[moira.log.event-emitter :as event-emitter]))

(defn start [state]
(defn start
"Create an [[moira.log.event-emitter/EventEmitter|EventEmitter] instance and
store it as part of the module's `state`."

[state]

(assoc state :event-emitter (event-emitter/create)))

(defn stop [{:keys [event-emitter]}]
(defn stop
"Wrap up [[moira.log.event-emitter/EventEmitter|EventEmitter] instance and
clear module's `state`."

[{:keys [event-emitter]}]

(event-emitter/unlisten event-emitter)
nil)

(s/def ::export (s/map-of #{:off :on :put} ifn?))

(defn export [{:keys [event-emitter]}]
(defn export
"Export API for interacting with the Application Log."

[{:keys [event-emitter]}]

{:post [(s/valid? ::export %)]}

{:off (partial event-emitter/unlisten event-emitter)
:on (partial event-emitter/listen event-emitter)
:put (partial event-emitter/emit event-emitter)})

(def default {:export #'export
:start #'start
:stop #'stop})
(def default
"Defaults that will automatically be injected into each
[[moira.application/Application|Application]] as `:app-log`."

{:export #'export
:start #'start
:stop #'stop})
3 changes: 1 addition & 2 deletions src/moira/log/txs.cljs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
(ns moira.log.txs
"Interceptors for integrating `:app-log` into the
[[moira.transition|transition]] flow."
"Integrate `:app-log` into the [[moira.transition|transition]] flow."

(:require [moira.log.event-emitter :as event-emitter]
[moira.log.module :as log.module]
Expand Down

0 comments on commit 4ad50f6

Please sign in to comment.