Skip to content

Commit

Permalink
Merge pull request #314 from frerom/with-meta
Browse files Browse the repository at this point in the history
Add IWithMeta protocol to RAtom
  • Loading branch information
Deraen authored Oct 20, 2017
2 parents a1a051f + 5463bd8 commit 0b38b44
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/reagent/ratom.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
7 changes: 7 additions & 0 deletions test/reagenttest/testratom.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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))))

0 comments on commit 0b38b44

Please sign in to comment.