Liking cljdoc? Tell your friends :D

Add side dependency

(ns darkleaf.di.tutorial.x-add-side-dependency-test
  (:require
   [clojure.test :as t]
   [darkleaf.di.core :as di]))

Actually, the rest of the di/start arguments are middlewares. Maps and collections are special cases of ones. Middlewares allow us to implement extra features.

In this test I'll show you how to perform a side effect like a database migration.

(defn root
  {::di/kind :component}
  []
  'root)

(defn migrations
  {::di/kind :component}
  [{::keys [*migrated?]}]
  (reset! *migrated? true))

(t/deftest add-side-dependency-test
  (let [*migrated? (atom false)]
    (with-open [root (di/start `root
                               (di/add-side-dependency `migrations)
                               {::*migrated? *migrated?})]
      (t/is @*migrated?)
      (t/is (= 'root @root)))))

Can you improve this documentation?Edit on GitHub

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close