mirror of https://github.com/status-im/reagent.git
Rename to with-let, add basic test
This commit is contained in:
parent
a73761e72e
commit
51163c1d07
|
@ -13,7 +13,7 @@
|
||||||
(deref co#)
|
(deref co#)
|
||||||
co#))
|
co#))
|
||||||
|
|
||||||
(defmacro with-kept [bindings & body]
|
(defmacro with-let [bindings & body]
|
||||||
(assert (vector? bindings))
|
(assert (vector? bindings))
|
||||||
(let [v (gensym "bind-v")
|
(let [v (gensym "bind-v")
|
||||||
bs (->> bindings
|
bs (->> bindings
|
||||||
|
@ -37,7 +37,7 @@
|
||||||
(when (== (.-ratomGeneration c#)
|
(when (== (.-ratomGeneration c#)
|
||||||
(.-generation ~v))
|
(.-generation ~v))
|
||||||
(js/console.error
|
(js/console.error
|
||||||
"The same with-kept is being used more than once in the
|
"The same with-let is being used more than once in the
|
||||||
same reactive context."))
|
same reactive context."))
|
||||||
(set! (.-generation ~v) (.-ratomGeneration c#))))
|
(set! (.-generation ~v) (.-ratomGeneration c#))))
|
||||||
(let ~bs
|
(let ~bs
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
(ns reagenttest.testreagent
|
(ns reagenttest.testreagent
|
||||||
(:require [cljs.test :as t :refer-macros [is deftest testing]]
|
(:require [cljs.test :as t :refer-macros [is deftest testing]]
|
||||||
[reagent.ratom :as rv :refer-macros [reaction]]
|
[reagent.ratom :as rv :refer-macros [reaction with-let]]
|
||||||
[reagent.debug :refer-macros [dbg println log]]
|
[reagent.debug :refer-macros [dbg println log]]
|
||||||
[reagent.interop :refer-macros [.' .!]]
|
[reagent.interop :refer-macros [.' .!]]
|
||||||
[reagent.core :as r]))
|
[reagent.core :as r]))
|
||||||
|
@ -565,3 +565,23 @@
|
||||||
c2 (fn []
|
c2 (fn []
|
||||||
[c1 (sorted-map 1 "foo" 2 "bar")])]
|
[c1 (sorted-map 1 "foo" 2 "bar")])]
|
||||||
(is (= (rstr [c2]) "<div>foo</div>"))))
|
(is (= (rstr [c2]) "<div>foo</div>"))))
|
||||||
|
|
||||||
|
(deftest basic-with-let
|
||||||
|
(let [n1 (atom 0)
|
||||||
|
n2 (atom 0)
|
||||||
|
n3 (atom 0)
|
||||||
|
val (r/atom 0)
|
||||||
|
c (fn []
|
||||||
|
(with-let [v (swap! n1 inc)]
|
||||||
|
(swap! n2 inc)
|
||||||
|
[:div @val]
|
||||||
|
(finally
|
||||||
|
(swap! n3 inc))))]
|
||||||
|
(with-mounted-component [c]
|
||||||
|
(fn [_ div]
|
||||||
|
(is (= [1 1 0] [@n1 @n2 @n3]))
|
||||||
|
(swap! val inc)
|
||||||
|
(is (= [1 1 0] [@n1 @n2 @n3]))
|
||||||
|
(r/flush)
|
||||||
|
(is (= [1 2 0] [@n1 @n2 @n3]))))
|
||||||
|
(is (= [1 2 1] [@n1 @n2 @n3]))))
|
||||||
|
|
Loading…
Reference in New Issue