I like Mount, a lot. But
- I wanted a composable and data-driven API (see this and this mount issue, and this presentation).
- I had my own ideas about how to handle redefinition of states.
- I don't need ClojureScript support (or its CLJC mode).
- I don't need suspending (or other features) - but I did have some own feature ideas for a library like this.
Mount Lite is Clojure only, has a flexible data-driven API, substitutions are well supported (and cleaner in my opinion), states stop automatically and cascadingly on redefinition, states can define bindings for looser coupling and states can be started and stopped in parallel. That's it.
You like it? Feel free to use it. Don't like it? The original Mount is great!
NOTE: This blog post explains in more detail why mount-lite was created and what it offers.
Documentation
Put this in your dependencies [functionalbytes/mount-lite "0.9.7"]
and make sure Clojars is one of your repositories.
Also make sure you use Clojure 1.7+, as the library uses transducers and volatiles.
NOTE: Clojure 1.8 - with its direct linking - is safe to use as well.
You can find all the documentation about mount-lite, what makes it unique, and the API by clicking on the link below:
A primer
Require the mount.lite
namespace, and other namespaces you depend on.
(ns your.app
(:require [mount.lite :refer (defstate) :as mount]
[your.app.config :as config] ;; <-- Also has a defstate.
[some.db.lib :as db]))
Define a defstate var, including the :start
and :stop
lifecycle expressions.
(defstate db
:start (db/start (get-in config/config [:db :url]))
:stop (db/stop db))
;=> #'your.app/db
Then start all defstates, use (start)
.
A sequence of started state vars is returned.
The order in which the states are started is determined by their load order by the Clojure compiler.
Calling (stop)
stops all the states in reverse order.
(mount/start)
;=> (#'your.app.config/config #'your.app/db)
db
;=> object[some.db.Object 0x12345678]
(mount/stop)
;=> (#'your.app/db #'your.app.config/config)
db
;=> #object[mount.lite.Unstarted 0x263571dd "State #'your.app/db is not started."]
That's it, enjoy!
License
Copyright © 2016 Functional Bytes
Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.