Last active
April 5, 2016 20:06
-
-
Save tolitius/ec9dbd8e92f2127e1418256214db0544 to your computer and use it in GitHub Desktop.
mount: catching not started
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn deref-state [name] | |
(let [{:keys [status inst] :as state} (@meta-state name)] | |
(when-not (:started status) | |
(up name state (atom #{}))) | |
@inst)) | |
(defn throw-not-started [name] | |
(throw-runtime (str "can't use \"" name "\" state, since it was not started. " | |
"this would usually happen if you forget to start it explicitly " | |
"or to \":require\" this state or its namespace, " | |
"in which case it would not be compiled (i.e. the Clojure Compiler would not see it)."))) | |
#?(:clj | |
(deftype DerefableState [name] | |
clojure.lang.IDeref | |
(deref [_] (deref-state name)) | |
clojure.lang.IFn | |
(invoke [_] (throw-not-started name)) | |
(applyTo [this _] (.invoke this)) | |
(invoke [this _] (.invoke this)) | |
(invoke [this _ _] (.invoke this)) | |
(invoke [this _ _ _] (.invoke this)))) | |
#?(:cljs | |
(deftype DerefableState [name] | |
IDeref | |
(-deref [_] (deref-state name)) | |
IFn | |
(-invoke [_] (throw-not-started name)) | |
(-invoke [this _] (.invoke this)) | |
(-invoke [this _ _] (.invoke this)) | |
(-invoke [this _ _ _] (.invoke this)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment