Skip to content

Commit

Permalink
remove trivial-factory
Browse files Browse the repository at this point in the history
  • Loading branch information
darkleaf committed Jan 20, 2025
1 parent e9e79ea commit d330569
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 29 deletions.
34 changes: 7 additions & 27 deletions src/darkleaf/di/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -160,31 +160,11 @@
(defn- nil-registry [key]
nil)

(defn- trivial-factory [factory]
;; nil has default implementation
(when (some? factory)
(reify
p/Factory
(dependencies [_]
(p/dependencies factory))
(build [_ deps]
(p/build factory deps))
(demolish [_ obj]
(p/demolish factory obj))
p/FactoryDescription
(description [_]
(?? (not-empty (p/description factory))
{::kind :trivial
:object factory})))))

(defn- trivial-registry [map key]
(trivial-factory (get map key)))

(defn- apply-middleware [registry middleware]
(cond
(fn? middleware) (middleware registry)
(map? middleware) (fn [key]
(?? (trivial-registry middleware key)
(?? (middleware key)
(registry key)))
(seqable? middleware) (reduce apply-middleware
registry middleware)
Expand Down Expand Up @@ -563,10 +543,8 @@
own-keys (cons f-key arg-keys)
own-factories (cons f args)
own-factories (for [factory own-factories]
(-> factory
trivial-factory
(u/update-description assoc
::update-key-target target)))
(u/update-description factory assoc
::update-key-target target))
own-registry (zipmap own-keys own-factories)
target-factory (registry target)]
(when (nil? target-factory)
Expand Down Expand Up @@ -735,7 +713,6 @@

(defn- var->factory-default [variable]
(-> @variable
trivial-factory
(u/update-description assoc ::variable variable)))

(defn- var->factory [variable]
Expand All @@ -762,7 +739,10 @@

Object
(description [this]
{}))
(if (instance? (:on-interface p/Factory) this)
{}
{::kind :trivial
:object this})))

(c/derive ::root ::instance)
(c/derive ::template ::instance)
Expand Down
3 changes: 1 addition & 2 deletions test/darkleaf/di/tutorial/x_inspect_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@
(t/deftest variable+factory-test
(t/is (= [(implicit-root `variable+factory)
{:key `variable+factory
:description {::di/kind :trivial
:object variable+factory
:description {#_"NOTE: no description as it is not implemented"
::di/variable #'variable+factory}}]
(di/inspect `variable+factory))))

Expand Down

0 comments on commit d330569

Please sign in to comment.