reagent-project / reagent

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

Test two ways to get regular atoms work in reactive context #547

Open Deraen opened 3 years ago

Deraen commented 3 years ago

Related to #546

react name is already so overloaded that I think we want to avoid that.

Looks like just calling notify-deref-watcher! is enough. That function doesn't modify the atom itself, but stores reference to current reactive context to the atom. Reagent will then use IWatchable -add-watch (and -remove-watch) to make reactive context to listen to this atom. Because regular atom implements this protocol same as Ratom.

While it would be simple to just provide single function to use instead of regular deref to use with normal atoms, I think better API might be to provide function to wrap atoms, so we can replace deref implementation. This way we could later also modify other methods, if necessary for some reason.

pepijndevos commented 3 years ago

Maybe the watch function should pass the wrapper reference?