Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update docs to give example of associng a bean #75

Open
mfikes opened this issue Sep 11, 2019 · 3 comments
Open

Update docs to give example of associng a bean #75

mfikes opened this issue Sep 11, 2019 · 3 comments

Comments

@mfikes
Copy link
Owner

mfikes commented Sep 11, 2019

In the Object Extraction doc (https://github.com/mfikes/cljs-bean/blob/master/doc/object.md) it gives an example where associng a string key causes a snapshot.

The doc should be updated to describe that associng a map value also causes a snapshot. The doc can describe how associng a bean can be used as a workaround to avoid snapshotting.

@martinklepsch
Copy link

(-> (cljs-bean/->clj #js {:some "data"})
    (assoc ::more (cljs-bean/->clj #js {:data "foo"})))

Here's an example of the workaround. I didn't completely understand what you meant the first time you mentioned it, but now it clicked. Thanks 🙂

@martinklepsch
Copy link

I'm also curious, does it make a difference to do something like this? i.e. will it cause a snapshot?

(-> (cljs-bean/->clj #js {:some "data"})
    (assoc-in [::more :data] "foo"))

@mfikes
Copy link
Owner Author

mfikes commented Sep 29, 2019

@martinklepsch Yes, that would cause a snapshot as well because it is like

(let [m (cljs-bean/->clj #js {:some "data"})]
   (assoc m ::more (assoc-in (get m ::more) [:data] "foo")))

and that inner assoc-in operates on nil, producing a persistent map.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants