mirror of https://github.com/status-im/reagent.git
This commit is contained in:
commit
f00ca03f70
4
Makefile
4
Makefile
|
@ -15,11 +15,11 @@ run: figwheel
|
||||||
|
|
||||||
# development build with auto-reloading and site generation
|
# development build with auto-reloading and site generation
|
||||||
runsite:
|
runsite:
|
||||||
@$(MAKE) run PROF=dev,site,$(PROF)
|
@$(MAKE) run PROF=+site,$(PROF)
|
||||||
|
|
||||||
# development build with figwheel, but no tests
|
# development build with figwheel, but no tests
|
||||||
runnotest:
|
runnotest:
|
||||||
@$(MAKE) run PROF=dev-notest,$(PROF)
|
@$(MAKE) run PROF=+dev-notest,$(PROF)
|
||||||
|
|
||||||
# production build with auto-rebuild
|
# production build with auto-rebuild
|
||||||
runprod: clean
|
runprod: clean
|
||||||
|
|
|
@ -8,7 +8,9 @@ var run = function (src) {
|
||||||
vm.runInThisContext(fs.readFileSync(src), 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 googDir = path.join(outputDir, "goog");
|
||||||
var optNone = false;
|
var optNone = false;
|
||||||
if (outputDir) {
|
if (outputDir) {
|
||||||
|
@ -21,13 +23,16 @@ var loadSrc = function (mainFile, outputDir, devModule) {
|
||||||
}
|
}
|
||||||
global.CLOSURE_IMPORT_SCRIPT = function (src) {
|
global.CLOSURE_IMPORT_SCRIPT = function (src) {
|
||||||
var s = path.resolve(path.resolve(cwd, path.join(googDir, src)));
|
var s = path.resolve(path.resolve(cwd, path.join(googDir, src)));
|
||||||
run(s);
|
if (!(s in imported)) {
|
||||||
return true;
|
imported[s] = true;
|
||||||
|
run(s);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
run(path.join(googDir, "base.js"));
|
run(path.join(googDir, "base.js"));
|
||||||
run(path.join(outputDir, "cljs_deps.js"));
|
run(path.join(outputDir, "cljs_deps.js"));
|
||||||
goog.require(devModule);
|
run(path.join(outputDir, devFile));
|
||||||
} else {
|
} else {
|
||||||
run(mainFile);
|
run(mainFile);
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ var cljsLoad = require("./cljs-load");
|
||||||
|
|
||||||
var srcFile = "outsite/public/js/main.js";
|
var srcFile = "outsite/public/js/main.js";
|
||||||
var outputDirectory = "outsite/public/js/out/";
|
var outputDirectory = "outsite/public/js/out/";
|
||||||
var moduleName = "reagentdemo.dev";
|
var devFile = "reagentdemo/dev.js";
|
||||||
|
|
||||||
var beep = "\u0007";
|
var beep = "\u0007";
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ if (typeof location === "undefined") {
|
||||||
|
|
||||||
var gensite = function () {
|
var gensite = function () {
|
||||||
console.log("Loading " + srcFile);
|
console.log("Loading " + srcFile);
|
||||||
var optNone = cljsLoad.load(srcFile, outputDirectory, moduleName);
|
var optNone = cljsLoad.load(srcFile, outputDirectory, devFile);
|
||||||
sitetools.core.genpages({"opt-none": optNone});
|
sitetools.core.genpages({"opt-none": optNone});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
(ns ^:figwheel-always reagentdemo.core
|
(ns reagentdemo.core
|
||||||
(:require [reagent.core :as reagent :refer [atom]]
|
(:require [reagent.core :as reagent :refer [atom]]
|
||||||
[reagent.interop :as i :refer-macros [.' .!]]
|
[reagent.interop :as i :refer-macros [.' .!]]
|
||||||
[clojure.string :as string]
|
[clojure.string :as string]
|
||||||
|
@ -39,6 +39,9 @@
|
||||||
[tools/page-content]
|
[tools/page-content]
|
||||||
[github-badge]])
|
[github-badge]])
|
||||||
|
|
||||||
(tools/start! {:body [#'demo]
|
(defn init! []
|
||||||
:css-infiles ["site/public/css/examples.css"
|
(tools/start! {:body [#'demo]
|
||||||
"site/public/css/main.css"]})
|
:css-infiles ["site/public/css/examples.css"
|
||||||
|
"site/public/css/main.css"]}))
|
||||||
|
|
||||||
|
(init!)
|
||||||
|
|
|
@ -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"}))
|
|
16
project.clj
16
project.clj
|
@ -3,11 +3,11 @@
|
||||||
:license {:name "MIT"}
|
:license {:name "MIT"}
|
||||||
:description "A simple ClojureScript interface to React"
|
:description "A simple ClojureScript interface to React"
|
||||||
|
|
||||||
:dependencies [[org.clojure/clojure "1.6.0"]
|
:dependencies [[org.clojure/clojure "1.7.0-RC1"]
|
||||||
[org.clojure/clojurescript "0.0-2816"]
|
[org.clojure/clojurescript "0.0-3308"]
|
||||||
[cljsjs/react "0.12.2-5"]]
|
[cljsjs/react "0.13.3-0"]]
|
||||||
|
|
||||||
:plugins [[lein-cljsbuild "1.0.4"]
|
:plugins [[lein-cljsbuild "1.0.6"]
|
||||||
[codox "0.8.12"]]
|
[codox "0.8.12"]]
|
||||||
|
|
||||||
:source-paths ["src"]
|
:source-paths ["src"]
|
||||||
|
@ -19,16 +19,16 @@
|
||||||
{:builds {:client {:source-paths ["test"]}}}}
|
{:builds {:client {:source-paths ["test"]}}}}
|
||||||
|
|
||||||
:dev [:test
|
:dev [:test
|
||||||
{:dependencies [[figwheel "0.2.3-SNAPSHOT"]]
|
{:dependencies [[figwheel "0.3.3"]]
|
||||||
:plugins [[lein-figwheel "0.2.3-SNAPSHOT"]]
|
:plugins [[lein-figwheel "0.3.3"]]
|
||||||
:source-paths ["demo"] ;; for lighttable
|
:source-paths ["demo"] ;; for lighttable
|
||||||
:resource-paths ["site" "outsite"]
|
:resource-paths ["site" "outsite"]
|
||||||
:figwheel {:css-dirs ["site/public/css"]}
|
:figwheel {:css-dirs ["site/public/css"]}
|
||||||
:cljsbuild
|
:cljsbuild
|
||||||
{:builds
|
{:builds
|
||||||
{:client
|
{:client
|
||||||
{:source-paths ["env/dev"]
|
{:figwheel {:on-jsload "reagenttest.runtests/reload"}
|
||||||
:compiler {:main "reagentdemo.dev"
|
:compiler {:main "reagenttest.runtests"
|
||||||
:source-map true
|
:source-map true
|
||||||
:source-map-timestamp true
|
:source-map-timestamp true
|
||||||
:optimizations :none
|
:optimizations :none
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
(ns reagent.debug)
|
(ns reagent.debug
|
||||||
|
(:require-macros [reagent.debug]))
|
||||||
|
|
||||||
;; Empty file, to allow require with :refer-macros
|
|
||||||
|
|
|
@ -1,3 +1,2 @@
|
||||||
(ns reagent.interop)
|
(ns reagent.interop
|
||||||
|
(:require-macros [reagent.interop]))
|
||||||
;; Empty
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
(ns reagent.ratom)
|
(ns reagent.ratom
|
||||||
|
(:refer-clojure :exclude [run!]))
|
||||||
|
|
||||||
(defmacro reaction [& body]
|
(defmacro reaction [& body]
|
||||||
`(reagent.ratom/make-reaction
|
`(reagent.ratom/make-reaction
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
(ns reagent.ratom
|
(ns reagent.ratom
|
||||||
(:refer-clojure :exclude [atom])
|
(:refer-clojure :exclude [atom])
|
||||||
(:require-macros [reagent.debug :refer (dbg log warn dev?)]
|
(:require-macros [reagent.ratom])
|
||||||
reagent.ratom)
|
(:require [reagent.impl.util :as util]
|
||||||
(:require [reagent.impl.util :as util]))
|
[reagent.debug :refer-macros [dbg log warn dev?]]))
|
||||||
|
|
||||||
(declare ^:dynamic *ratom-context*)
|
(declare ^:dynamic *ratom-context*)
|
||||||
|
|
||||||
|
@ -241,7 +241,7 @@
|
||||||
|
|
||||||
IComputedImpl
|
IComputedImpl
|
||||||
(-handle-change [this sender oldval newval]
|
(-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)
|
(set! dirty? true)
|
||||||
((or auto-run run) this)))
|
((or auto-run run) this)))
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
(ns ^:figwheel-always reagenttest.runtests
|
(ns reagenttest.runtests
|
||||||
(:require [reagenttest.testreagent]
|
(:require [reagenttest.testreagent]
|
||||||
[reagenttest.testcursor]
|
[reagenttest.testcursor]
|
||||||
[reagenttest.testinterop]
|
[reagenttest.testinterop]
|
||||||
|
@ -44,7 +44,14 @@
|
||||||
(js/setTimeout all-tests 100)
|
(js/setTimeout all-tests 100)
|
||||||
(all-tests)))
|
(all-tests)))
|
||||||
|
|
||||||
(when (some? (test/deftest empty-test))
|
(defn init! []
|
||||||
;; Only run with :load-tests true
|
(when (some? (test/deftest empty-test))
|
||||||
(reset! demo/test-results [#'test-output-mini])
|
;; Only run with :load-tests true
|
||||||
(run-tests))
|
(reset! demo/test-results [#'test-output-mini])
|
||||||
|
(run-tests)))
|
||||||
|
|
||||||
|
(defn reload []
|
||||||
|
(demo/init!)
|
||||||
|
(init!))
|
||||||
|
|
||||||
|
(init!)
|
||||||
|
|
|
@ -426,3 +426,19 @@
|
||||||
(swap! a update-in [:b] inc)
|
(swap! a update-in [:b] inc)
|
||||||
(is (= 4 (swap! b inc)))
|
(is (= 4 (swap! b inc)))
|
||||||
(is (= 4 @b))))
|
(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)))
|
||||||
|
|
Loading…
Reference in New Issue