diff --git a/Makefile b/Makefile index 00de469..e8503e0 100644 --- a/Makefile +++ b/Makefile @@ -15,11 +15,11 @@ run: figwheel # development build with auto-reloading and site generation runsite: - @$(MAKE) run PROF=dev,site,$(PROF) + @$(MAKE) run PROF=+site,$(PROF) # development build with figwheel, but no tests runnotest: - @$(MAKE) run PROF=dev-notest,$(PROF) + @$(MAKE) run PROF=+dev-notest,$(PROF) # production build with auto-rebuild runprod: clean diff --git a/bin/cljs-load.js b/bin/cljs-load.js index 440f7cc..27110eb 100644 --- a/bin/cljs-load.js +++ b/bin/cljs-load.js @@ -8,7 +8,9 @@ var run = function (src) { vm.runInThisContext(fs.readFileSync(src), src); } -var loadSrc = function (mainFile, outputDir, devModule) { +var imported = {}; + +var loadSrc = function (mainFile, outputDir, devFile) { var googDir = path.join(outputDir, "goog"); var optNone = false; if (outputDir) { @@ -21,13 +23,16 @@ var loadSrc = function (mainFile, outputDir, devModule) { } global.CLOSURE_IMPORT_SCRIPT = function (src) { var s = path.resolve(path.resolve(cwd, path.join(googDir, src))); - run(s); - return true; + if (!(s in imported)) { + imported[s] = true; + run(s); + return true; + } }; run(path.join(googDir, "base.js")); run(path.join(outputDir, "cljs_deps.js")); - goog.require(devModule); + run(path.join(outputDir, devFile)); } else { run(mainFile); } diff --git a/bin/gen-site.js b/bin/gen-site.js index ff8cffe..999da6e 100755 --- a/bin/gen-site.js +++ b/bin/gen-site.js @@ -3,7 +3,7 @@ var cljsLoad = require("./cljs-load"); var srcFile = "outsite/public/js/main.js"; var outputDirectory = "outsite/public/js/out/"; -var moduleName = "reagentdemo.dev"; +var devFile = "reagentdemo/dev.js"; var beep = "\u0007"; @@ -15,7 +15,7 @@ if (typeof location === "undefined") { var gensite = function () { console.log("Loading " + srcFile); - var optNone = cljsLoad.load(srcFile, outputDirectory, moduleName); + var optNone = cljsLoad.load(srcFile, outputDirectory, devFile); sitetools.core.genpages({"opt-none": optNone}); } diff --git a/demo/reagentdemo/core.cljs b/demo/reagentdemo/core.cljs index fbf57af..d846f7f 100644 --- a/demo/reagentdemo/core.cljs +++ b/demo/reagentdemo/core.cljs @@ -1,4 +1,4 @@ -(ns ^:figwheel-always reagentdemo.core +(ns reagentdemo.core (:require [reagent.core :as reagent :refer [atom]] [reagent.interop :as i :refer-macros [.' .!]] [clojure.string :as string] @@ -39,6 +39,9 @@ [tools/page-content] [github-badge]]) -(tools/start! {:body [#'demo] - :css-infiles ["site/public/css/examples.css" - "site/public/css/main.css"]}) +(defn init! [] + (tools/start! {:body [#'demo] + :css-infiles ["site/public/css/examples.css" + "site/public/css/main.css"]})) + +(init!) diff --git a/env/dev/reagentdemo/dev.cljs b/env/dev/reagentdemo/dev.cljs deleted file mode 100644 index fe61a3f..0000000 --- a/env/dev/reagentdemo/dev.cljs +++ /dev/null @@ -1,9 +0,0 @@ -(ns reagentdemo.dev - (:require [reagentdemo.core] - [reagenttest.runtests] - [reagent.core :as r] - [figwheel.client :as fw])) - -(when r/is-client - (fw/start - {:websocket-url "ws://localhost:3449/figwheel-ws"})) diff --git a/project.clj b/project.clj index 67057b5..65d09df 100644 --- a/project.clj +++ b/project.clj @@ -3,11 +3,11 @@ :license {:name "MIT"} :description "A simple ClojureScript interface to React" - :dependencies [[org.clojure/clojure "1.6.0"] - [org.clojure/clojurescript "0.0-2816"] - [cljsjs/react "0.12.2-5"]] + :dependencies [[org.clojure/clojure "1.7.0-RC1"] + [org.clojure/clojurescript "0.0-3308"] + [cljsjs/react "0.13.3-0"]] - :plugins [[lein-cljsbuild "1.0.4"] + :plugins [[lein-cljsbuild "1.0.6"] [codox "0.8.12"]] :source-paths ["src"] @@ -19,16 +19,16 @@ {:builds {:client {:source-paths ["test"]}}}} :dev [:test - {:dependencies [[figwheel "0.2.3-SNAPSHOT"]] - :plugins [[lein-figwheel "0.2.3-SNAPSHOT"]] + {:dependencies [[figwheel "0.3.3"]] + :plugins [[lein-figwheel "0.3.3"]] :source-paths ["demo"] ;; for lighttable :resource-paths ["site" "outsite"] :figwheel {:css-dirs ["site/public/css"]} :cljsbuild {:builds {:client - {:source-paths ["env/dev"] - :compiler {:main "reagentdemo.dev" + {:figwheel {:on-jsload "reagenttest.runtests/reload"} + :compiler {:main "reagenttest.runtests" :source-map true :source-map-timestamp true :optimizations :none diff --git a/src/reagent/debug.cljs b/src/reagent/debug.cljs index a6d1aa6..64cc3d0 100644 --- a/src/reagent/debug.cljs +++ b/src/reagent/debug.cljs @@ -1,3 +1,3 @@ -(ns reagent.debug) +(ns reagent.debug + (:require-macros [reagent.debug])) -;; Empty file, to allow require with :refer-macros diff --git a/src/reagent/interop.cljs b/src/reagent/interop.cljs index c4e7f83..078819c 100644 --- a/src/reagent/interop.cljs +++ b/src/reagent/interop.cljs @@ -1,3 +1,2 @@ -(ns reagent.interop) - -;; Empty +(ns reagent.interop + (:require-macros [reagent.interop])) diff --git a/src/reagent/ratom.clj b/src/reagent/ratom.clj index 11c8770..b14ced4 100644 --- a/src/reagent/ratom.clj +++ b/src/reagent/ratom.clj @@ -1,4 +1,5 @@ -(ns reagent.ratom) +(ns reagent.ratom + (:refer-clojure :exclude [run!])) (defmacro reaction [& body] `(reagent.ratom/make-reaction diff --git a/src/reagent/ratom.cljs b/src/reagent/ratom.cljs index 7b2308d..b796be2 100644 --- a/src/reagent/ratom.cljs +++ b/src/reagent/ratom.cljs @@ -1,8 +1,8 @@ (ns reagent.ratom (:refer-clojure :exclude [atom]) - (:require-macros [reagent.debug :refer (dbg log warn dev?)] - reagent.ratom) - (:require [reagent.impl.util :as util])) + (:require-macros [reagent.ratom]) + (:require [reagent.impl.util :as util] + [reagent.debug :refer-macros [dbg log warn dev?]])) (declare ^:dynamic *ratom-context*) @@ -241,7 +241,7 @@ IComputedImpl (-handle-change [this sender oldval newval] - (when (and active? (not dirty?) (not (identical? oldval newval))) + (when (and active? (not (identical? oldval newval))) (set! dirty? true) ((or auto-run run) this))) diff --git a/test/reagenttest/runtests.cljs b/test/reagenttest/runtests.cljs index 68d2553..1321d2e 100644 --- a/test/reagenttest/runtests.cljs +++ b/test/reagenttest/runtests.cljs @@ -1,4 +1,4 @@ -(ns ^:figwheel-always reagenttest.runtests +(ns reagenttest.runtests (:require [reagenttest.testreagent] [reagenttest.testcursor] [reagenttest.testinterop] @@ -44,7 +44,14 @@ (js/setTimeout all-tests 100) (all-tests))) -(when (some? (test/deftest empty-test)) - ;; Only run with :load-tests true - (reset! demo/test-results [#'test-output-mini]) - (run-tests)) +(defn init! [] + (when (some? (test/deftest empty-test)) + ;; Only run with :load-tests true + (reset! demo/test-results [#'test-output-mini]) + (run-tests))) + +(defn reload [] + (demo/init!) + (init!)) + +(init!) diff --git a/test/reagenttest/testcursor.cljs b/test/reagenttest/testcursor.cljs index 73f64bd..2afdc75 100644 --- a/test/reagenttest/testcursor.cljs +++ b/test/reagenttest/testcursor.cljs @@ -426,3 +426,19 @@ (swap! a update-in [:b] inc) (is (= 4 (swap! b inc))) (is (= 4 @b)))) + +(deftest test-double-reset + (let [a (r/atom {:foo {:active? false}}) + c (r/cursor a [:foo]) + f (fn [] + (swap! c assoc :not-pristine true) + (swap! a update-in [:foo :active?] not)) + spy (atom nil) + r (run! + (reset! spy (:active? @c)))] + (is (= @spy false)) + (f) + (is (= @spy true)) + (f) + (is (= @spy false)) + (dispose r)))