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

Question: Example of how to set a leaf node in an freactive cursor using swap! or reset! ? #55

Open
nottoseethesun opened this issue Jan 11, 2016 · 4 comments

Comments

@nottoseethesun
Copy link

Currently I run into No protocol method ISwap.-swap! defined for type boolean: true:

https://github.com/christopherbalz/vibrashank/blob/rerender-on-cursor-change/src/cljs/vibrashank/views.cljs#L62

The initial cursor is here:

https://github.com/christopherbalz/vibrashank/blob/rerender-on-cursor-change/src/cljs/vibrashank/core.cljs#L34

I do not see how to apply the examples on the Cursor section of the README to this common case.

What is an example of how to set a leaf node (say, that is a boolean) located greater than one level deep in a nested freactive cursor?

@DeLaGuardo
Copy link

Why you use freactive cursor with reagent? Maybe you need to look at reagent cursor?

@nottoseethesun
Copy link
Author

Thanks - yes we definitely looked at the reagent cursor, as iirc, we chose the freactive one for performance, as the reagent one would do something such as deref the entire cursor from the very top even if one only wanted to 'get' a single nested leaf value.

@DeLaGuardo
Copy link

You can deref reagent cursor same way as reagent atom.

(def state (reagent.core/atom {:foo {:bar {:baz true}}}))
(def baz (reagent.core/cursor state [:foo :bar :baz]))
@baz ; => true
(reset! baz false)
@baz ; => false

If you have questions email me directly, because all of this doesn't belong to freactive, imo)

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