File tree Expand file tree Collapse file tree
test/darkleaf/di/tutorial Expand file tree Collapse file tree Original file line number Diff line number Diff line change 780780 ~@body))
781781 (finally
782782 (.close resource#)))))))
783+
784+ (defn log [built-cb demolished-cb]
785+ (fn [registry]
786+ (fn [key]
787+ (let [factory (registry key)]
788+ (reify p/Factory
789+ (dependencies [_]
790+ (p/dependencies factory))
791+ (build [_ deps]
792+ (let [obj (p/build factory deps)]
793+ (built-cb key deps obj)
794+ obj))
795+ (demolish [_ obj]
796+ (p/demolish factory obj)
797+ (demolished-cb key obj)
798+ nil ))))))
Original file line number Diff line number Diff line change 1+ (ns darkleaf.di.tutorial.x-log-test
2+ (:require
3+ [clojure.test :as t]
4+ [darkleaf.di.core :as di]))
5+
6+ (defn a
7+ {::di/kind :component }
8+ []
9+ :a )
10+
11+ (defn b [{a `a}]
12+ :b )
13+
14+ (defn c
15+ {::di/kind :component }
16+ [{b `b}]
17+ :c )
18+
19+ (t/deftest log
20+ (let [logs (atom [])
21+ built! (fn [key deps obj]
22+ (swap! logs conj [:built key deps obj]))
23+ demolished! (fn [key obj]
24+ (swap! logs conj [:demolished key obj]))
25+ [a b c
26+ :as system] (di/start [`a `b `c]
27+ (di/log built! demolished!))]
28+ (di/stop system)
29+ (t/is (= [[:built `a {} a]
30+ [:built `b {`a a} b]
31+ [:built `c {`b b} c]
32+ [:built ::di/implicit-root {`a a `b b `c c} [a b c]]
33+ [:demolished ::di/implicit-root [a b c]]
34+ [:demolished `c c]
35+ [:demolished `b b]
36+ [:demolished `a a]]
37+ @logs))))
You can’t perform that action at this time.
0 commit comments