reagent icon indicating copy to clipboard operation
reagent copied to clipboard

Make track watchable

Open njordhov opened this issue 3 years ago • 2 comments

The Track type could benefit from being watchable by implementing the IWatchable protocol.

https://github.com/reagent-project/reagent/blob/4decfa65decdbf3742a7d598cf084a0f58d380b6/src/reagent/ratom.cljs#L216 https://github.com/reagent-project/reagent/blob/4decfa65decdbf3742a7d598cf084a0f58d380b6/src/reagent/ratom.cljs#L174-L177

njordhov avatar Sep 06 '20 23:09 njordhov

I looked into this, but I'm not sure if this makes sense.

Track doesn't really have a current value that could be watched. Track is backed by a Reaction, that does have a value, and Reactions have IWatchable implemented but I'm not completely sure how or when it works.

Seems like in case of reagent.core/track the Reaction value is only updated when the Track is deref'd. Otherwise, it is not following the dependencies and automatically updating the internal state. Thus the watch is not triggered without calling deref.

track! should start auto-running the reaction, so I think it keeps the internal state up to date. track! also returns the Reaction object, which can be watched.

Deraen avatar Nov 20 '20 09:11 Deraen

@Deraen Thanks for looking into it, and for all the work you do. I have since moved onto using track! instead of patching Track to make track watchable.

My use case included being able to use the same code for a reactive derefable within a reagent context as watched on toplevel.

njordhov avatar Nov 20 '20 23:11 njordhov