diff --git a/demo/reagentdemo/common.cljs b/demo/reagentdemo/common.cljs index 443dd30..1a1a1f7 100644 --- a/demo/reagentdemo/common.cljs +++ b/demo/reagentdemo/common.cljs @@ -1,9 +1,9 @@ (ns reagentdemo.common - (:require [reagent.core :as reagent :refer [atom]] + (:require [reagent.core :as r] [reagent.debug :refer-macros [dbg println]])) (defn demo-component [] - (let [showing (atom true)] + (let [showing (r/atom true)] (fn [{:keys [comp src complete no-heading]}] [:div (when comp diff --git a/demo/reagentdemo/core.cljs b/demo/reagentdemo/core.cljs index d846f7f..71ce252 100644 --- a/demo/reagentdemo/core.cljs +++ b/demo/reagentdemo/core.cljs @@ -1,5 +1,5 @@ (ns reagentdemo.core - (:require [reagent.core :as reagent :refer [atom]] + (:require [reagent.core :as r] [reagent.interop :as i :refer-macros [.' .!]] [clojure.string :as string] [sitetools.core :as tools :refer [link]] @@ -8,7 +8,7 @@ [reagentdemo.news :as news] [reagent.debug :refer-macros [dbg println]])) -(def test-results (atom nil)) +(def test-results (r/atom nil)) (def github {:href "https://github.com/reagent-project/reagent"}) diff --git a/demo/sitetools/core.cljs b/demo/sitetools/core.cljs index 0b26535..a1278f9 100644 --- a/demo/sitetools/core.cljs +++ b/demo/sitetools/core.cljs @@ -2,7 +2,7 @@ (:require [clojure.string :as string] [goog.events :as evt] [goog.history.EventType :as hevt] - [reagent.core :as reagent :refer [atom partial]] + [reagent.core :as r] [reagent.debug :refer-macros [dbg log dev?]] [reagent.interop :as i :refer-macros [.' .!]]) (:import [goog History] @@ -17,19 +17,19 @@ ;;; Configuration -(defonce config (atom {:page-map {"index.html" [:div "Empty"]} - :page-titles {} - :body [page-content] - :site-dir "outsite/public" - :css-infiles ["site/public/css/main.css"] - :css-file "css/built.css" - :js-file "js/main.js" - :js-dir "js/out" - :main-div "main-content" - :allow-html5-history false})) +(defonce config (r/atom {:page-map {"index.html" [:div "Empty"]} + :page-titles {} + :body [page-content] + :site-dir "outsite/public" + :css-infiles ["site/public/css/main.css"] + :css-file "css/built.css" + :js-file "js/main.js" + :js-dir "js/out" + :main-div "main-content" + :allow-html5-history false})) -(defonce page (atom "index.html")) -(defonce page-state (atom {:has-history false})) +(defonce page (r/atom "index.html")) +(defonce page-state (r/atom {:has-history false})) (defn register-page ([pageurl comp] @@ -60,7 +60,7 @@ (fn [e] (.preventDefault e) (reset! page p) - (reagent/next-tick + (r/next-tick #(set! (.-scrollTop (.-body js/document)) 0))) identity)) @@ -84,7 +84,7 @@ (add-watch page ::title-watch (fn [_ _ _ p] - (when reagent/is-client + (when r/is-client (set! (.-title js/document) (get-title))) ;; First title on a page wins #_(reset! page-title ""))) @@ -92,7 +92,7 @@ ;;; History (defn use-html5-history [] - (when reagent/is-client + (when r/is-client (let [proto (.' js/window :location.protocol)] (and (:allow-html5-history @config) (.isSupported Html5History) @@ -125,7 +125,7 @@ (reset! page (if (and tb (== 0 (.indexOf t tb))) (subs t (count tb)) t))) - (reagent/flush))) + (r/flush))) (add-watch page ::history (fn [_ _ oldp newp] (when-not (= oldp newp) @@ -167,7 +167,7 @@ main (str (:js-file c) timestamp) css-file (:css-file c) opt-none (:opt-none c)] - (reagent/render-to-static-markup + (r/render-to-static-markup [:html [:head [:meta {:charset "utf-8"}] @@ -186,7 +186,7 @@ (defn gen-page [page-name timestamp] (reset! page page-name) - (let [b (reagent/render-component-to-string (body))] + (let [b (r/render-component-to-string (body))] (str "" (html-template {:title (get-title) :body b @@ -234,7 +234,7 @@ (log "Generating site") (swap! config merge (js->clj opts :keywordize-keys true)) (let [dir (:site-dir @config) - written (atom #{}) + written (r/atom #{}) timestamp (str "?" (.' js/Date now)) one-page (fn [] (first (filter (fn [x] (nil? (@written x))) @@ -250,7 +250,7 @@ (defn start! [site-config] (swap! config merge site-config) - (when reagent/is-client + (when r/is-client (let [conf (when (exists? js/pageConfig) (js->clj js/pageConfig :keywordize-keys true)) page-name (:page-name conf)] @@ -260,6 +260,6 @@ (set-start-page page-name)) (setup-history page-name) (set! (.-title js/document) (get-title))) - (reagent/render-component (body) - (.' js/document getElementById - (:main-div @config)))))) + (r/render-component (body) + (.' js/document getElementById + (:main-div @config)))))) diff --git a/test/reagenttest/runtests.cljs b/test/reagenttest/runtests.cljs index 1321d2e..8a689b7 100644 --- a/test/reagenttest/runtests.cljs +++ b/test/reagenttest/runtests.cljs @@ -5,14 +5,14 @@ [reagenttest.testratom] [reagenttest.testwrap] [cljs.test :as test :include-macros true] - [reagent.core :as reagent :refer [atom]] + [reagent.core :as r] [reagent.interop :refer-macros [.' .!]] [reagent.debug :refer-macros [dbg log]] [reagentdemo.core :as demo])) (enable-console-print!) -(def test-results (atom nil)) +(def test-results (r/atom nil)) (def test-box-style {:position 'absolute :margin-left -35 @@ -40,7 +40,7 @@ (defn run-tests [] (reset! test-results nil) - (if reagent/is-client + (if r/is-client (js/setTimeout all-tests 100) (all-tests))) diff --git a/test/reagenttest/testcursor.cljs b/test/reagenttest/testcursor.cljs index 2afdc75..77fa32f 100644 --- a/test/reagenttest/testcursor.cljs +++ b/test/reagenttest/testcursor.cljs @@ -2,7 +2,7 @@ (:require [cljs.test :as t :refer-macros [is deftest testing]] [reagent.ratom :as rv :refer-macros [run! reaction]] [reagent.debug :refer-macros [dbg]] - [reagent.core :as r :refer [atom]])) + [reagent.core :as r])) ;; this repeats all the atom tests but using cursors instead @@ -244,8 +244,8 @@ (deftest test-equality - (let [a (atom {:foo "bar"}) - a1 (atom {:foo "bar"}) + (let [a (r/atom {:foo "bar"}) + a1 (r/atom {:foo "bar"}) c (r/cursor a [:foo]) foo (fn ([path] (get-in @a path)) @@ -285,7 +285,7 @@ (is (= @a {:foo "bar" :foobar "foo"})))) (deftest test-wrap - (let [a (atom {:foo "bar"}) + (let [a (r/atom {:foo "bar"}) w (r/wrap (:foo @a) swap! a assoc :foo)] (is (= @w "bar")) (is (= w (r/wrap "bar" swap! a assoc :foo))) @@ -301,7 +301,7 @@ (deftest cursor-values - (let [test-atom (atom {:a {:b {:c {:d 1}}}}) + (let [test-atom (r/atom {:a {:b {:c {:d 1}}}}) test-cursor (r/cursor test-atom [:a :b :c :d]) test-cursor2 (r/cursor test-atom []) runs (running)] ;; nasty edge case @@ -340,9 +340,9 @@ (deftest cursor-atom-behaviors - (let [test-atom (atom {:a {:b {:c {:d 1}}}}) + (let [test-atom (r/atom {:a {:b {:c {:d 1}}}}) test-cursor (r/cursor test-atom [:a :b :c :d]) - witness (atom nil) + witness (r/atom nil) runs (running)] ;; per the description, reset! should return the new values (is (= {} @@ -384,9 +384,9 @@ )) (deftest wrap-atom-behaviors - (let [test-atom (atom "foo") + (let [test-atom (r/atom "foo") test-wrap (r/wrap @test-atom reset! test-atom) - witness (atom nil)] + witness (r/atom nil)] ;; per the description, reset! should return the new values (is (= {} (reset! test-wrap {}))) @@ -418,7 +418,7 @@ )) (deftest test-cursor-swap - (let [a (atom {:b 1}) + (let [a (r/atom {:b 1}) b (r/cursor a [:b])] (is (= 1 @b)) (is (= 2 (swap! b inc))) @@ -433,7 +433,7 @@ f (fn [] (swap! c assoc :not-pristine true) (swap! a update-in [:foo :active?] not)) - spy (atom nil) + spy (r/atom nil) r (run! (reset! spy (:active? @c)))] (is (= @spy false)) diff --git a/test/reagenttest/testreagent.cljs b/test/reagenttest/testreagent.cljs index a49b7e8..2bf78a4 100644 --- a/test/reagenttest/testreagent.cljs +++ b/test/reagenttest/testreagent.cljs @@ -3,13 +3,13 @@ [reagent.ratom :as rv :refer-macros [reaction]] [reagent.debug :refer-macros [dbg println log]] [reagent.interop :refer-macros [.' .!]] - [reagent.core :as reagent :refer [atom]])) + [reagent.core :as r])) (defn running [] (rv/running)) -(def isClient reagent/is-client) +(def isClient r/is-client) -(def rflush reagent/flush) +(def rflush r/flush) (defn add-test-div [name] (let [doc js/document @@ -21,9 +21,9 @@ (defn with-mounted-component [comp f] (when isClient (let [div (add-test-div "_testreagent")] - (let [comp (reagent/render-component comp div #(f comp div))] - (reagent/unmount-component-at-node div) - (reagent/flush) + (let [comp (r/render-component comp div #(f comp div))] + (r/unmount-component-at-node div) + (r/flush) (.removeChild (.-body js/document) div))))) (defn found-in [re div] @@ -35,7 +35,7 @@ (deftest really-simple-test (when isClient - (let [ran (atom 0) + (let [ran (r/atom 0) really-simple (fn [] (swap! ran inc) [:div "div in really-simple"])] @@ -43,24 +43,24 @@ (fn [c div] (swap! ran inc) (is (found-in #"div in really-simple" div)) - (reagent/flush) + (r/flush) (is (= 2 @ran)) - (reagent/force-update-all) + (r/force-update-all) (is (= 3 @ran)))) (is (= 3 @ran))))) (deftest test-simple-callback (when isClient - (let [ran (atom 0) - comp (reagent/create-class + (let [ran (r/atom 0) + comp (r/create-class {:component-did-mount #(swap! ran inc) :render (fn [this] - (let [props (reagent/props this)] + (let [props (r/props this)] (is (map? props)) - (is (= props ((reagent/argv this) 1))) - (is (= 1 (first (reagent/children this)))) - (is (= 1 (count (reagent/children this)))) + (is (= props ((r/argv this) 1))) + (is (= 1 (first (r/children this)))) + (is (= 1 (count (r/children this)))) (swap! ran inc) [:div (str "hi " (:foo props) ".")]))})] (with-mounted-component (comp {:foo "you"} 1) @@ -71,45 +71,45 @@ (deftest test-state-change (when isClient - (let [ran (atom 0) - self (atom nil) - comp (reagent/create-class + (let [ran (r/atom 0) + self (r/atom nil) + comp (r/create-class {:get-initial-state (fn [] {:foo "initial"}) :reagent-render (fn [] - (let [this (reagent/current-component)] + (let [this (r/current-component)] (reset! self this) (swap! ran inc) - [:div (str "hi " (:foo (reagent/state this)))]))})] + [:div (str "hi " (:foo (r/state this)))]))})] (with-mounted-component (comp) (fn [C div] (swap! ran inc) (is (found-in #"hi initial" div)) - (reagent/replace-state @self {:foo "there"}) - (reagent/state @self) + (r/replace-state @self {:foo "there"}) + (r/state @self) (rflush) (is (found-in #"hi there" div)) - (reagent/set-state @self {:foo "you"}) + (r/set-state @self {:foo "you"}) (rflush) (is (found-in #"hi you" div)))) (is (= 4 @ran))))) (deftest test-ratom-change (when isClient - (let [ran (atom 0) + (let [ran (r/atom 0) runs (running) - val (atom 0) - secval (atom 0) + val (r/atom 0) + secval (r/atom 0) v1 (reaction @val) comp (fn [] (swap! ran inc) [:div (str "val " @v1 @val @secval)])] (with-mounted-component [comp] (fn [C div] - (reagent/flush) + (r/flush) (is (not= runs (running))) (is (found-in #"val 0" div)) (is (= 1 @ran)) @@ -119,13 +119,13 @@ (reset! val 1) (reset! val 2) (reset! val 1) - (reagent/flush) + (r/flush) (is (found-in #"val 1" div)) (is (= 2 @ran)) ;; should not be rendered (reset! val 1) - (reagent/flush) + (r/flush) (is (found-in #"val 1" div)) (is (= 2 @ran)))) (is (= runs (running))) @@ -133,9 +133,9 @@ (deftest batched-update-test [] (when isClient - (let [ran (atom 0) - v1 (atom 0) - v2 (atom 0) + (let [ran (r/atom 0) + v1 (r/atom 0) + v2 (r/atom 0) c2 (fn [{val :val}] (swap! ran inc) (is (= @v1 val)) @@ -167,14 +167,14 @@ (deftest init-state-test (when isClient - (let [ran (atom 0) + (let [ran (r/atom 0) really-simple (fn [] - (let [this (reagent/current-component)] + (let [this (r/current-component)] (swap! ran inc) - (reagent/set-state this {:foo "foobar"}) + (r/set-state this {:foo "foobar"}) (fn [] [:div (str "this is " - (:foo (reagent/state this)))])))] + (:foo (r/state this)))])))] (with-mounted-component [really-simple nil nil] (fn [c div] (swap! ran inc) @@ -183,9 +183,9 @@ (deftest shoud-update-test (when isClient - (let [parent-ran (atom 0) - child-ran (atom 0) - child-props (atom nil) + (let [parent-ran (r/atom 0) + child-ran (r/atom 0) + child-props (r/atom nil) f (fn []) f1 (fn []) child (fn [p] @@ -215,23 +215,23 @@ (is (= @child-ran 4) "symbols are equal") (do (reset! child-props {:style {:color 'red}}) (rflush)) (is (= @child-ran 5)) - (do (reset! child-props {:on-change (reagent/partial f)}) + (do (reset! child-props {:on-change (r/partial f)}) (rflush)) (is (= @child-ran 6)) - (do (reset! child-props {:on-change (reagent/partial f)}) + (do (reset! child-props {:on-change (r/partial f)}) (rflush)) (is (= @child-ran 6)) - (do (reset! child-props {:on-change (reagent/partial f1)}) + (do (reset! child-props {:on-change (r/partial f1)}) (rflush)) (is (= @child-ran 7)) - (reagent/force-update-all) + (r/force-update-all) (is (= @child-ran 8))))))) (deftest dirty-test (when isClient - (let [ran (atom 0) - state (atom 0) + (let [ran (r/atom 0) + state (r/atom 0) really-simple (fn [] (swap! ran inc) (if (= @state 1) @@ -248,7 +248,7 @@ (is (= 2 @ran))))) (defn as-string [comp] - (reagent/render-component-to-string comp)) + (r/render-component-to-string comp)) (deftest to-string-test [] (let [comp (fn [props] @@ -321,12 +321,12 @@ (as-string ['div#foo.foo.bar])))) (deftest partial-test [] - (let [p1 (reagent/partial vector 1 2)] + (let [p1 (r/partial vector 1 2)] (is (= (p1 3) [1 2 3])) - (is (= p1 (reagent/partial vector 1 2))) + (is (= p1 (r/partial vector 1 2))) (is (ifn? p1)) - (is (= (reagent/partial vector 1 2) p1)) - (is (not= p1 (reagent/partial vector 1 3))))) + (is (= (r/partial vector 1 2) p1)) + (is (not= p1 (r/partial vector 1 3))))) (deftest test-null-component (let [null-comp (fn [do-show] @@ -339,34 +339,34 @@ (deftest test-static-markup (is (= "
foo
" - (reagent/render-to-static-markup + (r/render-to-static-markup [:div "foo"]))) (is (= "

foo

" - (reagent/render-to-static-markup + (r/render-to-static-markup [:div.bar [:p "foo"]]))) (is (= "

foobar

" - (reagent/render-to-static-markup + (r/render-to-static-markup [:div.bar {:dangerously-set-inner-HTML {:__html "

foobar

"}} ])))) (deftest test-return-class (when isClient - (let [ran (atom 0) - top-ran (atom 0) + (let [ran (r/atom 0) + top-ran (r/atom 0) comp (fn [] (swap! top-ran inc) - (reagent/create-class + (r/create-class {:component-did-mount #(swap! ran inc) :render (fn [this] - (let [props (reagent/props this)] + (let [props (r/props this)] (is (map? props)) - (is (= props ((reagent/argv this) 1))) - (is (= 1 (first (reagent/children this)))) - (is (= 1 (count (reagent/children this)))) + (is (= props ((r/argv this) 1))) + (is (= 1 (first (r/children this)))) + (is (= 1 (count (r/children this)))) (swap! ran inc) [:div (str "hi " (:foo props) ".")]))})) - prop (atom {:foo "you"}) + prop (r/atom {:foo "you"}) parent (fn [] [comp @prop 1])] (with-mounted-component [parent] (fn [C div] @@ -376,25 +376,25 @@ (is (= 3 @ran)) (swap! prop assoc :foo "me") - (reagent/flush) + (r/flush) (is (found-in #"hi me" div)) (is (= 1 @top-ran)) (is (= 4 @ran))))))) (deftest test-return-class-fn (when isClient - (let [ran (atom 0) - top-ran (atom 0) + (let [ran (r/atom 0) + top-ran (r/atom 0) comp (fn [] (swap! top-ran inc) - (reagent/create-class + (r/create-class {:component-did-mount #(swap! ran inc) :component-function (fn [p a] (is (= 1 a)) (swap! ran inc) [:div (str "hi " (:foo p) ".")])})) - prop (atom {:foo "you"}) + prop (r/atom {:foo "you"}) parent (fn [] [comp @prop 1])] (with-mounted-component [parent] (fn [C div] @@ -404,17 +404,17 @@ (is (= 3 @ran)) (swap! prop assoc :foo "me") - (reagent/flush) + (r/flush) (is (found-in #"hi me" div)) (is (= 1 @top-ran)) (is (= 4 @ran))))))) (defn rstr [react-elem] - (reagent/render-to-static-markup react-elem)) + (r/render-to-static-markup react-elem)) (deftest test-create-element - (let [ae reagent/as-element - ce reagent/create-element] + (let [ae r/as-element + ce r/create-element] (is (= (rstr (ae [:div])) (rstr (ce "div")))) (is (= (rstr (ae [:div])) @@ -442,13 +442,13 @@ (fn [] (this-as this - (reagent/create-element + (r/create-element "div" #js{:className (.' this :props.className)} (.' this :props.children))))})) (deftest test-adapt-class - (let [d1 (reagent/adapt-react-class ndiv) - d2 (reagent/adapt-react-class "div")] + (let [d1 (r/adapt-react-class ndiv) + d2 (r/adapt-react-class "div")] (is (= (rstr [:div]) (rstr [d1]))) (is (= (rstr [:div "a"]) @@ -472,11 +472,11 @@ (rstr [d2 "a" "b" [:div "c"]]))))) (deftest test-reactize-component - (let [ae reagent/as-element - ce reagent/create-element + (let [ae r/as-element + ce r/create-element c1r (fn [p] [:p "p:" (:a p) (:children p)]) - c1 (reagent/reactify-component c1r)] + c1 (r/reactify-component c1r)] (is (= (rstr [:p "p:a"]) (rstr (ce c1 #js{:a "a"})))) (is (= (rstr [:p "p:"]) @@ -493,7 +493,7 @@ (ae [:i "i"]))))))) (deftest test-keys - (let [a nil ;; (atom "a") + (let [a nil ;; (r/atom "a") c (fn key-tester [] [:div (for [i (range 3)] diff --git a/test/reagenttest/testwrap.cljs b/test/reagenttest/testwrap.cljs index 2012746..f4377c8 100644 --- a/test/reagenttest/testwrap.cljs +++ b/test/reagenttest/testwrap.cljs @@ -1,7 +1,7 @@ (ns reagenttest.testwrap (:require [cljs.test :as t :refer-macros [is deftest]] [reagent.debug :refer-macros [dbg println log]] - [reagent.core :as r :refer [atom wrap]])) + [reagent.core :as r])) (defn add-test-div [name] (let [doc js/document @@ -26,7 +26,7 @@ false)))) (deftest test-wrap-basic - (let [state (atom {:foo 1}) + (let [state (r/atom {:foo 1}) ws (fn [] (r/wrap (:foo @state) swap! state assoc :foo))] (let [w1 (ws) w2 (ws)] @@ -72,8 +72,8 @@ (reset! w1 1)))) (deftest test-wrap-equality - (let [a (atom 1) - b (atom 2)] + (let [a (r/atom 1) + b (r/atom 2)] (is (= (r/wrap @a swap! a assoc :foo) (r/wrap @a swap! a assoc :foo))) (is (not= (r/wrap @a swap! a assoc :foo) @@ -98,8 +98,8 @@ (deftest test-wrap-returns (let [n (fn [] :foobar) - a (atom {:k 1}) - b (wrap {:k 1} n)] + a (r/atom {:k 1}) + b (r/wrap {:k 1} n)] (is (not= a b)) (is (not= b a)) (is (= (swap! a update-in [:k] inc) @@ -114,18 +114,18 @@ (deftest test-wrap (when r/is-client - (let [state (atom {:foo {:bar {:foobar 1}}}) - ran (atom 0) + (let [state (r/atom {:foo {:bar {:foobar 1}}}) + ran (r/atom 0) grand-state (clojure.core/atom nil) grand-child (fn [v] (swap! ran inc) (reset! grand-state v) [:div (str "value:" (:foobar @v) ":")]) child (fn [v] - [grand-child (wrap (:bar @v) + [grand-child (r/wrap (:bar @v) swap! v assoc :bar)]) parent (fn [] - [child (wrap (:foo @state) + [child (r/wrap (:foo @state) swap! state assoc :foo)])] (with-mounted-component [parent] (fn [c div] @@ -175,10 +175,10 @@ (is (= @ran 7))))))) (deftest test-cursor - (let [state (atom {:a 0 - :b 0}) - a-count (atom 0) - b-count (atom 0) + (let [state (r/atom {:a 0 + :b 0}) + a-count (r/atom 0) + b-count (r/atom 0) derefer (fn derefer [cur count] (swap! count inc) [:div @cur])