-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Document default Application Log implementation
- Loading branch information
Showing
3 changed files
with
28 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters