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] <javascript:;>.
> To post to this group, send email to [email protected]
> <javascript:;>.
> 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