From 5463bd84031c29c9961d150db7ed543921875361 Mon Sep 17 00:00:00 2001 From: Fredrik Roman Date: Thu, 5 Oct 2017 20:55:29 -0400 Subject: [PATCH] Add IWithMeta protocol to RAtom --- src/reagent/ratom.cljs | 3 +++ test/reagenttest/testratom.cljs | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/src/reagent/ratom.cljs b/src/reagent/ratom.cljs index 2cfaad47..393e6c63 100644 --- a/src/reagent/ratom.cljs +++ b/src/reagent/ratom.cljs @@ -146,6 +146,9 @@ (-swap! [a f x y] (-reset! a (f state x y))) (-swap! [a f x y more] (-reset! a (apply f state x y more))) + IWithMeta + (-with-meta [_ new-meta] (RAtom. state new-meta validator watches)) + IMeta (-meta [_] meta) diff --git a/test/reagenttest/testratom.cljs b/test/reagenttest/testratom.cljs index bf830369..9674cc1f 100644 --- a/test/reagenttest/testratom.cljs +++ b/test/reagenttest/testratom.cljs @@ -461,3 +461,10 @@ (r/flush) (dispose r1) (is (= runs (running))))) + +(deftest ratom-with-meta + (let [value {:val 1} + meta-value {:meta-val 1} + state (with-meta (r/atom value) meta-value)] + (is (= (meta state) meta-value)) + (is (= @state value)))) \ No newline at end of file