Rename to with-let, add basic test

This commit is contained in:
Dan Holmsand 2015-09-23 10:39:49 +02:00
parent a73761e72e
commit 51163c1d07
2 changed files with 23 additions and 3 deletions

View File

@ -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

View File

@ -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]) "<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]))))