[juxt.modular/co-dependency "0.2.0"]
(defproject your-project "your-version"
...
:dependencies [[tangrammer/co-dependency "0.1.3"]]
...
)
(ns your-app-ns
(:require [com.stuartsierra.component :as component]
[tangrammer.component.co-dependency :as co-dependency]))
Same as you do with stuartsierra/component lib but adding co-dependencies with co-dependency/co-using fn In this case :b depends on :a and :a co-depends on :b
(defn system-1 []
(map->System1 {:a (-> (component-a)
(co-dependency/co-using [:b]))
:b (-> (component-b)
(component/using [:a]))
:c (-> (component-c)
(component/using [:a :b]))
:d (-> (component-d)
(component/using {:b :b :c :c}))
:e (component-e)})
(def system-started-with-co-deps (co-dependency/start-system (system-1)))
(def a (-> system-started-with-co-deps :a))
(def a-from-b (:a @(-> system-started-with-co-deps :a :b)))
;; checking identity equality
(assert (= a a-from-b))
If you use stuartsierra "reloaded" workflow then update original stuartsierra dev/start function by:
(defn start
"Starts the current development system."
[]
(alter-var-root #'system co-dependency/start-system))
Follow the test provided to learn how to use it :)
In contrast with normal dependencies that you get using clojure map functions
(:dependency-key component)
;;=> dependency
when you want to retrieve a co-dependency you need to deref the co-dependency value
@(:co-dependency-key component)
;;=> co-dependency
Copyright © 2014 Juan Antonio Ruz (juxt.pro)
Distributed under the Eclipse Public License, the same as Clojure
Can you improve this documentation? These fine people already did:
tangrammer, Malcolm Sparks & juanantonioruzEdit on GitHub
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close