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

Make track watchable #510

Open
njordhov opened this issue Sep 6, 2020 · 2 comments
Open

Make track watchable #510

njordhov opened this issue Sep 6, 2020 · 2 comments

Comments

@njordhov
Copy link

njordhov commented Sep 6, 2020

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

(deftype Track [f args ^:mutable reaction]

IWatchable
(-notify-watches [this old new] (notify-w this old new))
(-add-watch [this key f] (add-w this key f))
(-remove-watch [this key] (remove-w this key))

@Deraen
Copy link
Member

Deraen commented Nov 20, 2020

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.

@njordhov
Copy link
Author

njordhov commented Nov 20, 2020

@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.

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

No branches or pull requests

2 participants