Skip to content

Commit

Permalink
refactoring & :kind :service
Browse files Browse the repository at this point in the history
  • Loading branch information
darkleaf committed Nov 9, 2024
1 parent 1ec9d37 commit 19017d7
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 23 deletions.
23 changes: 17 additions & 6 deletions src/darkleaf/di/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -528,11 +528,11 @@
args (map deps arg-keys)]
(apply f t args)))
(demolish [_ _])

p/FactoryDescription
(description [_]
{::middleware ::update-key
::target target}))
{:kind :middleware
:middleware ::update-key
:target target}))
own-registry (zipmap (cons f-key arg-keys)
(cons f args))
target-factory (registry target)]
Expand Down Expand Up @@ -630,7 +630,18 @@
(demolish [_ _])))

(defn- var->0-service [variable]
variable)
;; todo: meta ::service

(reify
p/Factory
(dependencies [_])
(build [_ _]
variable)
(demolish [_ _])
p/FactoryDescription
(description [_]
{:kind :service
:var variable})))

(defn- var->service [variable]
(let [deps (dependencies-fn variable)]
Expand Down Expand Up @@ -848,8 +859,8 @@
info (into {}
(filter (fn [[k v]] (some? v)))
{:key key
:dependencies declared-deps
:meta (p/description factory)})]
:dependencies (not-empty declared-deps)
:description (not-empty (p/description factory))})]
(reify p/Factory
(dependencies [_]
declared-deps)
Expand Down
44 changes: 27 additions & 17 deletions test/darkleaf/di/tutorial/x_inspect_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,41 @@
:or {b :default}}]
:ok)


(t/deftest zero-arity-service-test
(t/is (= [{:key ::di/implicit-root
:dependencies {`a :required}}
{:key `a
:description {:kind :service
:var #'a}}]
(di/inspect `a))))


;; todo: name
(t/deftest ok
(t/is (= [{:key ::di/implicit-root
:dependencies {`c :required}
:meta {}}
:dependencies {`c :required}}
{:key `c
:dependencies {`a :required `b :optional}
:meta {}}
{:key `a
:meta {}}
:dependencies {`a :required `b :optional}}
{:key `a
:description {:kind :service
:var #'a}}
{:key `b
:dependencies {`a :required}
:meta {}}]
:dependencies {`a :required}}]
(di/inspect `c))))

(t/deftest meta-test

(t/deftest update-key-test
(t/is (= [{:key ::di/implicit-root,
:dependencies {`a :required}
:meta {}}
:dependencies {`a :required}}
{:key `a,
:dependencies {`a+di-update-key#0-target :optional,
`a+di-update-key#0-f :optional}
:meta {::di/middleware ::di/update-key
::di/target `a}}
{:key `a+di-update-key#0-target
:meta {}}
{:key `a+di-update-key#0-f
:meta {}}]
:description {:kind :middleware
:middleware ::di/update-key
:target `a}}
{:key `a+di-update-key#0-target
:description {:kind :service
:var #'a}}
{:key `a+di-update-key#0-f}]
(di/inspect `a (di/update-key `a str)))))

0 comments on commit 19017d7

Please sign in to comment.