tolitius / mount

managing Clojure and ClojureScript app state since (reset)
Eclipse Public License 1.0
1.23k stars 89 forks source link

CLJS: can't find "cleanup-if-dirty" var unless in CLJC mode #44

Closed tolitius closed 8 years ago

tolitius commented 8 years ago
boot.user=> (start-repl)

cljs.user=> (require-macros '[mount.core :refer [defstate]])
nil
cljs.user=> (defstate a :start 42)

clojure.lang.ExceptionInfo: Unable to resolve var: cleanup-if-dirty in this context at line 1 <cljs repl> {:file "<cljs repl>", :line 1, :column 1, :tag :cljs/analysis-error}

cljs.user=>

cljs.user=> (require '[mount.core :as mount])
nil
cljs.user=> (mount/in-cljc-mode)
:cljc
cljs.user=> (defstate a :start 42)
#'cljs.user/a
cljs.user=> a
#object[mount.core.DerefableState]
cljs.user=> @a
42

thanks to @frankhenderson for reporting this. his sample project that confirms the behavior.

tolitius commented 8 years ago
boot.user=> (start-repl)
cljs.user=> (require-macros '[mount.core :refer [defstate]])
nil
cljs.user=> (defstate a :start 42)

clojure.lang.ExceptionInfo: Unable to resolve var: cleanup-if-dirty in this context at line 1 <cljs repl> {:file "<cljs repl>", :line 1, :column 1, :tag :cljs/analysis-error}

cljs.user=> (require '[mount.core :as mount])
nil
cljs.user=> (defstate a :start 42)
#'cljs.user/a

looks like client sources are simply compiled before mount sources. once mount is "looked at" by compiler once, all is good: i.e. (require '[mount.core]) at the entry level of the application should solve this.

most likely has to do with defstate being compiled at the earlier compilation stage (i.e. hence :require-macros)

a transparent mount compilation needs more thinking (i.e. ship an aot compliment jar, etc.), but at this point definitely needs to be documented.

tolitius commented 8 years ago

0.1.9 refactors defstate macro in a way that it no longer calls private functions directly.