[#10]: plugin cljs/figwheel; IDeref from cljs
This commit is contained in:
parent
da0922850a
commit
362036a3b9
5 changed files with 56 additions and 10 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
|
@ -4,7 +4,8 @@
|
||||||
pom.xml
|
pom.xml
|
||||||
pom.xml.asc
|
pom.xml.asc
|
||||||
.repl*
|
.repl*
|
||||||
dev-resources/
|
/dev-resources
|
||||||
|
/resources/public
|
||||||
figwheel_server.log
|
figwheel_server.log
|
||||||
*.jar
|
*.jar
|
||||||
*.class
|
*.class
|
||||||
|
|
|
||||||
31
project.clj
31
project.clj
|
|
@ -6,13 +6,36 @@
|
||||||
|
|
||||||
:source-paths ["src"]
|
:source-paths ["src"]
|
||||||
|
|
||||||
:dependencies [[org.clojure/clojure "1.7.0"]]
|
:dependencies [[org.clojure/clojure "1.7.0"]
|
||||||
|
[org.clojure/clojurescript "1.7.170"]]
|
||||||
|
|
||||||
:profiles {:dev {:source-paths ["dev" "test/app"]
|
:profiles {:dev {:source-paths ["dev" "test/app"]
|
||||||
:dependencies [[yesql "0.5.1"]
|
:dependencies [[ch.qos.logback/logback-classic "1.1.3"]
|
||||||
[ch.qos.logback/logback-classic "1.1.3"]
|
|
||||||
[org.clojure/tools.logging "0.3.1"]
|
[org.clojure/tools.logging "0.3.1"]
|
||||||
[robert/hooke "1.3.0"]
|
[robert/hooke "1.3.0"]
|
||||||
[org.clojure/tools.namespace "0.2.11"]
|
[org.clojure/tools.namespace "0.2.11"]
|
||||||
[org.clojure/tools.nrepl "0.2.11"]
|
[org.clojure/tools.nrepl "0.2.11"]
|
||||||
[com.datomic/datomic-free "0.9.5327" :exclusions [joda-time]]]}})
|
[com.datomic/datomic-free "0.9.5327" :exclusions [joda-time]]]
|
||||||
|
|
||||||
|
:plugins [[lein-cljsbuild "1.1.1"]
|
||||||
|
[lein-figwheel "0.5.0-2"]]
|
||||||
|
|
||||||
|
:cljsbuild {
|
||||||
|
:builds [{:id "dev"
|
||||||
|
:source-paths ["src" "test"]
|
||||||
|
:figwheel {:on-jsload "mount.example.cljs/on-js-reload" }
|
||||||
|
|
||||||
|
:compiler {:main mount.example.cljs
|
||||||
|
:asset-path "js/compiled/out"
|
||||||
|
:output-to "test/resources/public/js/compiled/mount.js"
|
||||||
|
:output-dir "test/resources/public/js/compiled/out"
|
||||||
|
:optimizations :none
|
||||||
|
:source-map true
|
||||||
|
:source-map-timestamp true
|
||||||
|
:cache-analysis true }}
|
||||||
|
{:id "prod"
|
||||||
|
:source-paths ["src" "test"]
|
||||||
|
:compiler {:output-to "test/resources/public/js/compiled/mount.js"
|
||||||
|
:main mount.example.cljs
|
||||||
|
:optimizations :advanced
|
||||||
|
:pretty-print false}}]}}})
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,9 @@
|
||||||
(ns mount.core
|
(ns #?(:clj mount.core
|
||||||
(:require [mount.tools.macro :refer [on-error throw-runtime] :as macro])
|
:cljs ^:figwheel-no-load mount.core)
|
||||||
#?(:cljs [mount.tools.cljs :as cljs]))
|
#?(:clj (:require [mount.tools.macro :refer [on-error throw-runtime] :as macro])
|
||||||
|
:cljs (:require [mount.tools.macro :as macro]
|
||||||
|
[mount.tools.cljs :as cljs]))
|
||||||
|
#?(:cljs (:require-macros [mount.tools.macro :refer [on-error throw-runtime]])))
|
||||||
|
|
||||||
(defonce ^:private -args (atom :no-args)) ;; mostly for command line args and external files
|
(defonce ^:private -args (atom :no-args)) ;; mostly for command line args and external files
|
||||||
(defonce ^:private state-seq (atom 0))
|
(defonce ^:private state-seq (atom 0))
|
||||||
|
|
@ -114,8 +117,11 @@
|
||||||
(update-meta! [state :status] #{:started}))))
|
(update-meta! [state :status] #{:started}))))
|
||||||
|
|
||||||
(deftype DerefableState [name]
|
(deftype DerefableState [name]
|
||||||
clojure.lang.IDeref
|
#?(:clj clojure.lang.IDeref
|
||||||
(deref [this]
|
:cljs IDeref)
|
||||||
|
(#?(:clj deref
|
||||||
|
:cljs -deref)
|
||||||
|
[_]
|
||||||
(let [{:keys [status inst] :as state} (@meta-state name)]
|
(let [{:keys [status inst] :as state} (@meta-state name)]
|
||||||
(when-not (:started status)
|
(when-not (:started status)
|
||||||
(up name state (atom #{})))
|
(up name state (atom #{})))
|
||||||
|
|
|
||||||
10
test/mount/example/cljs.cljs
Normal file
10
test/mount/example/cljs.cljs
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
(ns mount.example.cljs
|
||||||
|
(:require [mount.core :as mount])
|
||||||
|
(:require-macros [mount.core :refer [defstate]]))
|
||||||
|
|
||||||
|
(enable-console-print!)
|
||||||
|
|
||||||
|
(println "hi from mount!")
|
||||||
|
|
||||||
|
(defn on-js-reload []
|
||||||
|
"reloading js..")
|
||||||
6
test/resources/public/index.html
Normal file
6
test/resources/public/index.html
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<body>
|
||||||
|
<script src="js/compiled/mount.js" type="text/javascript"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Loading…
Reference in a new issue