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

Dereferencing to automatically trigger an update... like Reagent #16

Closed
Frozenlock opened this issue Nov 22, 2014 · 14 comments
Closed

Dereferencing to automatically trigger an update... like Reagent #16

Frozenlock opened this issue Nov 22, 2014 · 14 comments

Comments

@Frozenlock
Copy link

First of all, this is amazing stuff.

The notion of having a pure cljs 'react' is very exciting.
Being able to use any tag is very convenient.

I was wondering if it was possible to somehow do the same thing as reagent:
No need for rx, the simple act of deferencing capture everything that's needed.

Any component that dereferences a reagent.core/atom will be automatically re-rendered.

@ul
Copy link
Contributor

ul commented Nov 22, 2014

I think this contradicts a little bit to core idea of freactive. Because, as far as I understand, freactive tries to deliver changes to exact place (dom node, attributes or styles), not to entire component.

@aaronc
Copy link
Owner

aaronc commented Nov 22, 2014

Yeah, so as Ruslan was just explaining the model for freactive is a bit different. A component in freactive is basically created by passing something that is "derefable" (implements cljs.core/IDeref) and watchable (implements cljs.core/IWatchable and/or freactive.core/IInvalidates) as a child node or attribute. There is no other type of component. So, if you want to get reactive binding you'll need to have something that is "derefable" and watchable. The rx macro does not create a component itself but just something that is "deferable" and watchable which returns an up-to-date representation of your user interface whenever it is deref'ed. The framework then knows how to make a binding on that "derefable"/watchable thing - this binding could have lifecycle callbacks a la React.

So, it is a slightly different model. After talking with several people at Clojure/conj about this, I realize that the way this model works may need a bit more explaining than I've given it so I definitely intend to write some more detailed docs about this. For those coming from the React/Reagent/Om model, I think what I'm doing may seem a little strange at first, but I'm pretty sure that once one "groks" it, it will make sense... What it allows one to do is direct binding which is inherently more efficient than diffing for most cases (I do have experimental diffing to support other cases if that should be needed).

So the Regeant syntax for component instantiation - although it is less typing - may not be more clear. In my mind, it adds a degree of "complection" (using Rich Hickey's terminology) which just isn't necessary once we have our own component (binding) model not tied to React.

Let me know if this explanation makes sense. I'm trying to figure out the best way to communicate this model.

@sparkofreason
Copy link

Is this why add-watch doesn't seem to work with an rx expression? See

https://gist.github.com/sparkofreason/a42420c3f9572de5c82d

I never see output for the :c*d watch.

@aaronc
Copy link
Owner

aaronc commented Apr 21, 2015

add-watch should work on rx's. Could be a bug in 0.1.0 though. Have you tried it with 0.2.0-SNAPSHOT? Also you probably just want to use (cursor x :b), (cursor b :c) in most cases...

@sparkofreason
Copy link

I tried with both 0.1.0 and 0.2.0-SNAPSHOT, same result.

Agreed on using (cursor x :b) form, I'm just playing around to get my head around the whole lens/cursor idea in general.

@aaronc
Copy link
Owner

aaronc commented Apr 21, 2015 via email

@aaronc
Copy link
Owner

aaronc commented Apr 21, 2015

Oops, I looked at your example again and see that you're doing that. Just
trying to think about what could be causing this bug...

On Tue, Apr 21, 2015 at 11:58 AM, Aaron Craelius [email protected]
wrote:

If you try dereferencing the c*d before you add the watch does that help?

@sparkofreason
Copy link

Actually, it works if I deref it twice before adding the watch.

@aaronc
Copy link
Owner

aaronc commented Apr 22, 2015 via email

@sparkofreason
Copy link

Thanks, will look into other implementations if I need them. Not sure I will, as long as DOM updates work correctly. I'm experimenting using freactive to build HTML custom elements in ClojureScript (https://github.com/allgress/cereus). Looks pretty solid so far (albeit with very limited testing), and a vast improvement over my previous attempt using React-like virtual DOM.

@aaronc
Copy link
Owner

aaronc commented Apr 22, 2015

Nice :)

On Wed, Apr 22, 2015 at 11:54 AM, Dave Dixon [email protected]
wrote:

Thanks, will look into other implementations if I need them. Not sure I
will, as long as DOM updates work correctly. I'm experimenting using
freactive to build HTML custom elements in ClojureScript (
https://github.com/allgress/cereus). Looks pretty solid so far (albeit
with very limited testing), and a vast improvement over my previous attempt
using React-like virtual DOM.


Reply to this email directly or view it on GitHub
#16 (comment).

@GetContented
Copy link

It's possible that issue 44 would solve this issue... #44 (rallying support)

@aaronc
Copy link
Owner

aaronc commented Jun 1, 2015

0.2.0 will probably support Reagent's [my-component-fn ...] either by default or via some plugin.

@aaronc
Copy link
Owner

aaronc commented Jun 10, 2015

Reagent's [my-component-fn ...] syntax is now supported in the develop branch because it was very easy to implement and this may make it easier for some people to get started. It is however officially "discouraged" (as it encourages less-direct binding than freactive supports). Reagent's with-meta callbacks are obviously not supported. Closing this.

@aaronc aaronc closed this as completed Jun 10, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants