reagent-project / reagent

A minimalistic ClojureScript interface to React.js
http://reagent-project.github.io/
MIT License
4.75k stars 415 forks source link

-peek-at cursors #157

Closed mhuebert closed 6 years ago

mhuebert commented 9 years ago

I'm working on a project in which sometimes I want to dereference a cursor inside a component without triggering a reaction (eg. I want to show the value but only re-render on some other event).

I found -peek-at in ratom.cljs and saw that it does exactly what I need, so I put IComputedImpl in RCursor and copied over the same implementation as was in Reaction. It appears to work exactly as intended (I'm fairly new to protocols and types in Clojure so I wasn't sure the best way to make the change).

Is this something that might be added to master or is there a reason not to provide -peek-at ability to cursors?

mike-thompson-day8 commented 8 years ago

@mhuebert Adding this would fine. I too have had situations where this would be useful.

holmsand commented 8 years ago

Yes, that might be a good idea. In the meantime, you can use something like

(swap! some-atom identity)
mike-thompson-day8 commented 8 years ago

@holmsand I don't understand this swap! idea.

As I understand it, @mhuebert wishes he could use (peek-at ratom) to get the value out of the ratom without having that ratom captured. (deref ratom) does the same but causes the ratom to be captured.

Later now I see. A magnificent hack!!
For anyone else as slow as I am ... Dan is suggesting that (swap! some-atom identity) will return the same value as @some-atom returns, except the swap! version won't cause some-atom to be captured (as an input signal to the enclosing reaction).

holmsand commented 8 years ago

swap! returns the value produced by identity, which will be the original value of the ratom - and doesn't capture a deref.

On 30 okt. 2015, at 12:30, Mike Thompson notifications@github.com wrote:

@holmsand I don't understand this swap! idea.

As I understand it, @mhuebert wishes he could use (peek-at ratom) to get the value out of the ratom without having that ratom captured. (deref ratom) does the same but causes the ratom to be captured.

— Reply to this email directly or view it on GitHub.

gadfly361 commented 6 years ago

I think recent tools such as: re-frisk and data-frisk-reagent solve this 'want'.

If not, @mhuebert, please feel free to re-open this issue.