Name: modular.co-dependency
Owner: JUXT
Description: Co-dependency support for com.stuartsierra.component
Created: 2015-03-19 12:29:10.0
Updated: 2015-03-27 13:11:31.0
Pushed: 2015-12-18 10:48:08.0
Homepage: null
Size: 26
Language: Clojure
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
t.modular/co-dependency "0.2.0"]
project your-project "your-version"
..
dependencies [[juxt.modular/co-dependency "0.2.0"]]
..
your-app-ns
require [com.stuartsierra.component :refer (using)]
[modular.component.co-dependency :refer (co-using)]))
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
n system-1 []
ap->System1 {:a (-> (component-a)
(co-using [:b]))
:b (-> (component-b)
(using [:a]))
:c (-> (component-c)
(using [:a :b]))
:d (-> (component-d)
(using {:b :b :c :c}))
:e (component-e)})
system-started-with-co-deps (co-dependency/start-system (system-1)))
a (-> system-started-with-co-deps :a))
a-from-b (:a @(-> system-started-with-co-deps :a :b)))
hecking identity equality
ert (= a a-from-b))
If you use stuartsierra “reloaded” workflow then update original stuartsierra dev/start function by:
n start
tarts the current development system."
lter-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
pendency-key component)
dependency
when you want to retrieve a co-dependency you need to deref the co-dependency value
o-dependency-key component)
co-dependency
Co-dependencies are bound after a component's start phase. Therefore, a component's co-dependencies will not be accessible, even via a dereference of the co-dependency, during a component's start.
Re-read that last paragraph until you understand that you cannot make
use of a co-dependency's data until after the start
phase of a given
component. You can make use of a co-dependency's data after the
component has been fully started, which usually means in a function
(such as a Ring handler).
The penalty for not understanding this point is days spent figuring out
why you can't see a co-dependency's data. It's because you're still
trying to access this data within the start
phase of your
component. Don't do this. Defer the lookup until after the entire start
phase of your system has completed.
Copyright © 2014 Juan Antonio Ruz (juxt.pro)
Distributed under the Eclipse Public License, the same as Clojure