diff --git a/src/reagent/ratom.clj b/src/reagent/ratom.clj index 2acaaa5..2758871 100644 --- a/src/reagent/ratom.clj +++ b/src/reagent/ratom.clj @@ -13,7 +13,7 @@ (deref co#) co#)) -(defmacro with-kept [bindings & body] +(defmacro with-let [bindings & body] (assert (vector? bindings)) (let [v (gensym "bind-v") bs (->> bindings @@ -37,7 +37,7 @@ (when (== (.-ratomGeneration c#) (.-generation ~v)) (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.")) (set! (.-generation ~v) (.-ratomGeneration c#)))) (let ~bs diff --git a/test/reagenttest/testreagent.cljs b/test/reagenttest/testreagent.cljs index 718b052..b588e28 100644 --- a/test/reagenttest/testreagent.cljs +++ b/test/reagenttest/testreagent.cljs @@ -1,6 +1,6 @@ (ns reagenttest.testreagent (: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.interop :refer-macros [.' .!]] [reagent.core :as r])) @@ -565,3 +565,23 @@ c2 (fn [] [c1 (sorted-map 1 "foo" 2 "bar")])] (is (= (rstr [c2]) "
foo
")))) + +(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]))))