Skip to content

Commit

Permalink
meta not preserved with assoc, dissoc, conj (#21)
Browse files Browse the repository at this point in the history
Fixes #20
  • Loading branch information
mfikes committed Jun 17, 2019
1 parent 3789630 commit bd77a0c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -5,6 +5,7 @@ All notable changes to this project will be documented in this file. This change

### Fixed
- `TransientBean` should be private ([#17](https://github.com/mfikes/cljs-bean/issues/17))
- meta not preserved with `assoc`, `dissoc`, `conj` ([#20](https://github.com/mfikes/cljs-bean/issues/20))

## [0.5.0] - 2019-06-15
### Added
Expand Down
6 changes: 3 additions & 3 deletions src/cljs_bean/core.cljs
Expand Up @@ -262,10 +262,10 @@
IAssociative
(-assoc [_ k v]
(if (compatible-key? k prop->key)
(Bean. nil
(Bean. meta
(doto (gobj/clone obj) (unchecked-set (key->prop k) v))
prop->key key->prop nil nil)
(-assoc (snapshot obj prop->key) k v)))
(-assoc (with-meta (snapshot obj prop->key) meta) k v)))

(-contains-key? [coll k]
(contains? coll k))
Expand All @@ -282,7 +282,7 @@
deleted? (js-delete obj' (key->prop k))
cnt' (when (and __cnt deleted?)
(dec __cnt))]
(Bean. nil obj' prop->key key->prop cnt' nil)))
(Bean. meta obj' prop->key key->prop cnt' nil)))

ICounted
(-count [_]
Expand Down
18 changes: 14 additions & 4 deletions test/cljs_bean/core_test.cljs
Expand Up @@ -113,12 +113,22 @@
(deftest meta-test
(let [o (bean #js {:a 1})]
(count o)
(= {:foo true} (meta (with-meta o {:foo true})))
(== 1 (count (with-meta o {:foo true}))))
(is (= {:foo true} (meta (with-meta o {:foo true}))))
(is (== 1 (count (with-meta o {:foo true})))))
(let [o (bean #js {:a 1} :keywordize-keys false)]
(count o)
(= {:foo true} (meta (with-meta o {:foo true})))
(== 1 (count (with-meta o {:foo true})))))
(is (= {:foo true} (meta (with-meta o {:foo true}))))
(is (== 1 (count (with-meta o {:foo true})))))
(let [m {:x 1}]
(is (= m (meta (dissoc (with-meta (bean #js {:a 1}) m) :a))))
(is (= m (meta (dissoc (with-meta (bean #js {:a 1}) m) :b)))))
(let [m {:x 1}]
(is (= m (meta (assoc (with-meta (bean #js {:a 1}) m) :b 2))))
(is (= m (meta (assoc (with-meta (bean #js {:a 1}) m) :a 1))))
(is (= m (meta (assoc (with-meta (bean #js {:a 1}) m) "c" 1)))))
(let [m {:x 1}]
(is (= m (meta (conj (with-meta (bean #js {:a 1}) m) [:b 2]))))
(is (= m (meta (conj (with-meta (bean #js {:a 1}) m) [:a 1]))))))

(deftest conj-test
(let [b (bean #js {:x 1})
Expand Down

0 comments on commit bd77a0c

Please sign in to comment.