I'd like some beginner help with application state.

The browser-side clojurescript I'm writing happens to hook into a react
library like Quiescent (I started with Om, then went to Reagent and now I'm
thinking Quiescent might fit better ... it's up in the air).  I'm storing
all the component state built from requests to the server in a single atom
and I realized I made a mistake by:

1) passing the atom to the state management function(s) (which should be
fine)
2) running the value of the atom through various control flow / conditional
execution
3) calling swap! on the atom based on decisions made in step 2

Now, in general that's the wrong way to treat an atom because state might
have changed between getting its value, making decisions and then changing
its value shortly thereafter, even though I'm only calling this from a
single thread and the browser's javascript engine can only run in a single
thread.

Instead I could write a pure function that takes the state value plus
server input and spits out new state, and then run that through swap!.
Great.  However, in the event the atom gets a new value I need to trigger
q/render.  I could put side-effects that conditionally calls q/render in
the state management function but that would be run inside swap! which of
course shouldn't have any side effects because swap!s can be retried (even
though we're presently in this strictly single-threaded browser
environment).

I want to write quality code so maybe the thing to do is to add a watch to
the state atom so that, in the event the value of the atom changes I can
re-run q/render.  Now within the watch I can either verify the atom value
has /actually/ changed by comparing old and new or I can just ignore it
because that's something react is good at doing anyway.  Plus I would only
call q/render on a requestAnimationFrame so some unnecessary calls to
q/render wouldn't be big deal.

But now I wonder if I've traveled in a circle and arrived back at Reagent,
with it's ratoms and automatic calls to re-render when things change.

Or do any of you handle large components very differently?

-- 
Note that posts from new members are moderated - please be patient with your 
first post.
--- 
You received this message because you are subscribed to the Google Groups 
"ClojureScript" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojurescript+unsubscr...@googlegroups.com.
To post to this group, send email to clojurescript@googlegroups.com.
Visit this group at http://groups.google.com/group/clojurescript.

Reply via email to