Back

resolve-key (clj)

(source)

multimethod

(resolve-key key value)
Return a value to substitute for a reference prior to initiation. By default the value of the key is returned unaltered. This can be used to hide information that is only necessary to halt or suspend the key.

Examples

integrant
(ns integrant.core-test
  (:require #?(:clj  [clojure.test :refer [are deftest is testing]]
               :cljs [cljs.test :refer-macros [are deftest is testing]])
            [integrant.core :as ig]
            [weavejester.dependency :as dep]))

(defmethod ig/init-key ::r [_ v] {:v v})
(defmethod ig/resolve-key ::r [_ {:keys [v]}] v)
(defmethod ig/resume-key ::r [k v _ _] (ig/init-key k v))

  (testing "with custom resolve-key"
    (let [m (ig/init {::a (ig/ref ::r), ::r 1})]
      (is (= m {::a [1], ::r {:v 1}}))))

  (testing "with custom resolve-key"
    (let [c  {::a (ig/ref ::r), ::r 1}
          m  (ig/init c)
          _  (ig/suspend! m)
          m' (ig/resume c m)]
      (is (= m m'))))