mount => mount.core. fixes #11

This commit is contained in:
anatoly 2015-11-17 00:09:45 -05:00
parent 10a7625742
commit ab0b611978
10 changed files with 24 additions and 22 deletions

View file

@ -64,7 +64,7 @@ mount is an alternative to the [component](https://github.com/stuartsierra/compo
## How
```clojure
(require '[mount :refer [defstate]])
(require '[mount.core :refer [defstate]])
```
### Creating State
@ -126,7 +126,7 @@ There are of course direct dependecies that `mount` respects:
```clojure
(ns app.config
(:require [mount :refer [defstate]]))
(:require [mount.core :refer [defstate]]))
(defstate app-config
:start (load-config "test/resources/config.edn"))
@ -136,7 +136,7 @@ this `app-config`, being top level, can be used in other namespaces, including t
```clojure
(ns app.database
(:require [mount :refer [defstate]]
(:require [mount.core :refer [defstate]]
[app.config :refer [app-config]]))
(defstate conn :start (create-connection app-config))
@ -151,6 +151,8 @@ is an example of a Datomic connection that "depends" on a similar `app-config`.
accordingly: i.e. will call their `:start` and `:stop` defined functions. Hence the whole applicatoin state can be reloaded in REPL e.g.:
```
dev=> (require '[mount.core :as mount])
dev=> (mount/stop)
dev=> (mount/start)
```

View file

@ -15,7 +15,7 @@
[clojure.tools.namespace.repl :as tn]
[check.parts-test]
[check.start-with-test]
[mount]
[mount.core :as mount]
[app :refer [create-nyse-schema find-orders add-order]])) ;; <<<< replace this your "app" namespace(s) you want to be available at REPL time
(defn start []

View file

@ -4,7 +4,7 @@
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:source-paths ["src" "src/mount"]
:source-paths ["src"]
:dependencies [[org.clojure/clojure "1.7.0"]
[ch.qos.logback/logback-classic "1.1.3"]

View file

@ -1,4 +1,4 @@
(ns mount
(ns mount.core
(:require [clojure.tools.macro :as macro]
[clojure.tools.namespace.repl :refer [disable-reload!]]
[clojure.tools.logging :refer [info warn debug error]]))

View file

@ -1,7 +1,7 @@
(ns app
(:require [datomic.api :as d]
[clojure.tools.nrepl.server :refer [start-server stop-server]]
[mount :refer [defstate]]
[mount.core :as mount :refer [defstate]]
[app.utils.datomic :refer [touch]]
[app.config :refer [app-config]]
[app.nyse :as nyse]))

View file

@ -1,5 +1,5 @@
(ns app.config
(:require [mount :refer [defstate]]
(:require [mount.core :as mount :refer [defstate]]
[clojure.edn :as edn]
[clojure.tools.logging :refer [info]]))

View file

@ -1,5 +1,5 @@
(ns app.nyse
(:require [mount :refer [defstate]]
(:require [mount.core :as mount :refer [defstate]]
[datomic.api :as d]
[clojure.tools.logging :refer [info]]
[app.config :refer [app-config]]))

View file

@ -1,5 +1,5 @@
(ns check.parts-test
(:require [mount :refer [defstate] :as m]
(:require [mount.core :as mount :refer [defstate] :as m]
[app.nyse :refer [conn]]
[clojure.test :refer :all]))
@ -14,4 +14,4 @@
(deftest start-only-parts
(is (instance? datomic.peer.LocalConnection conn))
(is (instance? mount.NotStartedState should-not-start)))
(is (instance? mount.core.NotStartedState should-not-start)))

View file

@ -1,5 +1,5 @@
(ns check.start-with-test
(:require [mount :refer [defstate] :as m]
(:require [mount.core :as mount :refer [defstate]]
[app.config :refer [app-config]]
[app.nyse :refer [conn]]
[app :refer [nrepl]]
@ -13,15 +13,15 @@
(deftest start-with
(testing "should start with substitutes"
(let [_ (m/start-with {#'app.nyse/conn #'check.start-with-test/test-conn
#'app/nrepl #'check.start-with-test/test-nrepl})]
(let [_ (mount/start-with {#'app.nyse/conn #'check.start-with-test/test-conn
#'app/nrepl #'check.start-with-test/test-nrepl})]
(is (map? app-config))
(is (vector? nrepl))
(is (= conn 42))
(mount/stop)))
(testing "should start normally after start-with"
(let [_ (m/start)]
(let [_ (mount/start)]
(is (map? app-config))
(is (instance? clojure.tools.nrepl.server.Server nrepl))
(is (instance? datomic.peer.LocalConnection conn))
@ -30,11 +30,11 @@
(mount/stop)))
(testing "should start-without normally after start-with"
(let [_ (m/start-without #'check.start-with-test/test-conn
#'check.start-with-test/test-nrepl)]
(let [_ (mount/start-without #'check.start-with-test/test-conn
#'check.start-with-test/test-nrepl)]
(is (map? app-config))
(is (instance? clojure.tools.nrepl.server.Server nrepl))
(is (instance? datomic.peer.LocalConnection conn))
(is (instance? mount.NotStartedState test-conn))
(is (instance? mount.NotStartedState test-nrepl))
(is (instance? mount.core.NotStartedState test-conn))
(is (instance? mount.core.NotStartedState test-nrepl))
(mount/stop))))

View file

@ -1,5 +1,5 @@
(ns check.start-without-test
(:require [mount :as m]
(:require [mount.core :as m]
[app.config :refer [app-config]]
[app.nyse :refer [conn]]
[app :refer [nrepl]]
@ -14,5 +14,5 @@
(deftest start-without-states
(is (map? app-config))
(is (instance? mount.NotStartedState nrepl))
(is (instance? mount.NotStartedState conn)))
(is (instance? mount.core.NotStartedState nrepl))
(is (instance? mount.core.NotStartedState conn)))