I think this is a mistake. It's been reported multiple times on this
list that accessing cursors outside of the render loop did seem to
work, and each time David Nolen insisted that you're not supposed to
do that and it only appears to work. (I'd add that deref'ing the
cursor during the render loop also appears to work, and you're
apparently not supposed to do that either.)

My understanding is that you run the risk of getting inconsistent
values. I'd guess that in this case it works because the :id is never
changed, but I must admit my use of Om has been rather casual so I
don't feel like I can offer any definitive answer here. My
recommendation would be to follow the official documentation, which
clearly states that outside the render loop you should explicitly
deref.

Now, if your question was more about what is and is not the render
phase, I think the render phase is just the "render" function call
(when it's invoked by React) and every code that it calls
synchronously. Anything asynchronous (event handlers, go blocks, and
generally any callbacks you'd pass to an asynchronous function) that
is called from the render function (or a function it calls, etc.), or
anything that you yourself do outside of the React-invoked render
calls, is outside the render phase.

On 9 August 2015 at 10:06, Asher Coren <[email protected]> wrote:
>
> On Sunday, August 9, 2015 at 10:50:57 AM UTC+3, Gary Verhaegen wrote:
> > You deref if you want to get the current value. The argument to om/update!, 
> > however, must be a cursor, not a random value.
> >
> >
> > In this particular case, the code uses om/update! because it does not need 
> > to use the old value to compute the new one. Since the code of submit does 
> > not seem to require the value at the cursor, there is no need to deref.
> >
> > On Sunday, 9 August 2015, Asher Coren <[email protected]> wrote:
> > Hello,
> >
> >
> >
> > I'm trying to understand when we must deref a cursor to get its value.
> >
> >
> >
> > In the om cursors wiki (https://github.com/omcljs/om/wiki/Cursors) it 
> > states that
> >
> > event handlers are considered not part of the render phase, and therefore 
> > cursors in handlers should be drefed.
> >
> > Same is shown in the Basic-tutorial 
> > (https://github.com/omcljs/om/wiki/Basic-Tutorial):
> >
> >
> >
> > (defn contact-view [contact owner]
> >
> >  (reify
> >
> >    om/IRenderState
> >
> >    (render-state [this {:keys [delete]}]
> >
> >      (dom/li nil
> >
> >        (dom/span nil (display-name contact))
> >
> >        (dom/button #js {:onClick (fn [e] (put! delete @contact))} 
> > "Delete")))))
> >
> >
> >
> > But, in the TodoMVC code 
> > (https://github.com/swannodette/todomvc/blob/gh-pages/labs/architecture-examples/om/src/todomvc/item.cljs),
> >  the handlers (onclick, onchange...) use the cursor without drefing it:
> >
> >
> >
> > (defn submit [e todo owner comm]
> >
> >  (when-let [edit-text (om/get-state owner :edit-text)]
> >
> >    (if-not (string/blank? (.trim edit-text))
> >
> >      (do
> >
> >        (om/update! todo :title edit-text)
> >
> >        (put! comm [:save todo]))
> >
> >      (put! comm [:destroy todo])))
> >
> >  false)
> >
> >
> >
> > So, what is the correct way?
> >
> >
> >
> > Thank you.
> >
> >
> >
> > --
> >
> > 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 [email protected].
> >
> > To post to this group, send email to [email protected].
> >
> > Visit this group at http://groups.google.com/group/clojurescript.
>
> Gary,
> Thank you for your reply. I realize now that I pasted the wrong part of code. 
> Your explanation is correct with regards to `om/update!`. But, later in the 
> code we have:
>     (dom/button
>       #js {:className "destroy"
>       :onClick (fn [_] (put! comm [:destroy todo]))}))
>
> Here again we send the cursor itself (`todo`) without derefing. When reading 
> from the channel, it is used like this:
> (defn destroy-todo [app {:keys [id]}]
>   (om/transact! app :todos
>     (fn [todos] (into [] (remove #(= (:id %) id) todos)))
>     [:delete id]))
>
> Here we require the value of the cursor ({:keys [id}) - but we sent it 
> without derefing!
>
> --
> 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 [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/clojurescript.

-- 
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/clojurescript.

Reply via email to