integrant

2018-01-09T18:03:23.000234Z

I am trying to setup a simple integrant config, but the compiler chokes in the #ig/ref tag - what am I missing? Thx… `(ns hello-integrant.hi-test (:require [integrant.core :as ig] [clojure.edn :as edn])) (def config {[:attrs :test] {:attr1 “attr1-val”} [:hello-integrant.hi-test/test-data :read] {:path “resources/test_data.edn”} [:hello-integrant.hi-test/test-data :def] {:data #ig/ref [:hello-integrant.hi-test/test-data :read] :attrs #ig/ref [:graph-attrs :test]}}) (defmethod ig/init-key [:attrs :test] [_ {:keys [attrs]}] attrs) (defmethod ig/init-key [::test-data :read] [_ {:keys [path]}] ;;don’t slurp path for now {:mydata :anything}) (defmethod ig/init-key [::test-data :def] [_ {:keys [data attrs]}] (println :DATA data :ATTRS) (def data-map {:d data :a attrs})) `

2018-01-09T18:04:55.000481Z

@kingcode Use (ig/ref :blah) instead. The #ig/ref tag is added to the ig/read function, but not to data_readers.clj.

2018-01-09T18:05:29.000755Z

Also be aware that keywords without namespaces can’t be derived in Clojure, so all keys in the configuration must be namespaced.

2018-01-09T18:07:23.000316Z

@weavejester Thank you very much for the advice, and for your great work!….(ig/ref ..) worked, but I had other issues which led me to this one…I probably will have more questions 🙂

2018-01-09T18:07:58.000373Z

No problem. I’ll be sitting in this channel for a while yet.

2018-01-09T18:10:51.000280Z

@weavejester indeed, it looks like my other issue is namespaced-keyword related, will try your suggestion..

2018-01-09T18:17:07.000717Z

Also, the keys used in init-key have to be a single keyword I believe.

2018-01-09T18:20:06.000339Z

@weavejester ah, that’s what it is then - I was using [:ns1/kw1 :ns2/kw2] dispatch values in my defmethods: 1. Caused by java.lang.IllegalArgumentException No method in multimethod ‘init-key’ for dispatch value: :integrant.composite/hackenbush.graph-attrs+hackenbush.test_21739

2018-01-09T18:20:38.000201Z

@weavejester so it is necessary to use derive to leverage compound keys in the config?

2018-01-09T18:20:58.000401Z

Composite keys are just a shortcut for using derive.

2018-01-09T18:21:13.000396Z

So this:

{[::foo ::bar] {}}

2018-01-09T18:21:27.000500Z

Ah OK thx…I didn’t assimilate the use of derive to achieve that yet….will look into it.

2018-01-09T18:21:39.000414Z

Is equivalent to:

(derive ::foo+bar ::foo)
(derive ::foo+bar ::bar)
{::foo+bar {}}

2018-01-09T18:22:00.000172Z

@weavejester thank you much! Great videos also…thx

2018-01-09T18:22:10.000801Z

Thanks 🙂