aaronc/freactive

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

Opened this issue · 4 comments

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?

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

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.

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)