Am Mittwoch, 12. März 2014 17:23:04 UTC+1 schrieb David Nolen:
> Om renders on requestAnimationFrame. That means by the time your handler
> executes it may not have an accurate picture of the application state.
> Cursors cannot be directly manipulated outside of the consistent phase of the
> application (render). You can however *deref* the cursor in your handler to
> get the most recent value:
>
>
>
> (defmulti handle-change (fn [e state owner] (:validate @state)))
I thought so, too, and tried that allready. Up came another exception:
"Uncaught Error: No protocol method IDeref.-deref defined for type
cljs.core/PersistentArrayMap: {:text #<Ben>, :hint #<max. 30 Zeichen>,
:validate #<max-30>} "
I then tried @(:validate state), but that threw me the same exception...
That was when I concluded I didn't really understand state/cursors.
And, btw: *thanks*(!!) for om, it's a joy to work with!
/ Mathias
...
"
>
>
>
> HTH,
> David
>
>
>
>
> On Wed, Mar 12, 2014 at 12:07 PM, Mathias Picker <[email protected]> wrote:
>
> Hi all,
>
>
>
> I'm trying to understand om and build a simple input field with validation,
> hacked together from the tutorial.
>
>
>
> For some data like this
>
>
>
> {:key "name"
>
> :value "Ben"
>
> :hint "max. 30 Zeichen"
>
> :validate "max-30"}
>
>
>
> and a component like this:
>
>
>
> (defmulti handle-change (fn [e state owner] (:validate state)))
>
> (defmethod handle-change "max-30" [e state owner]
>
> (handle-change-max-30 e state owner))
>
> (defmethod handle-change :default [e state owner]
>
> (om/set-state! owner :hint "Que?"))
>
>
>
> (defn input-view [entry owner]
>
> (reify
>
> om/IInitState
>
> (init-state [this]
>
> {:text (:value entry)
>
> :hint (:hint entry)
>
> :validate (:validate entry)})
>
> om/IRenderState
>
> (render-state [this state]
>
> (dom/div nil
>
> (dom/input
>
> #js {:type "text"
>
> :value (:text state)
>
> :onChange #(handle-change % state owner)
>
> (dom/span nil (str " " (:hint state)))))))
>
>
>
>
>
> I get
>
>
>
> "Uncaught Error: Cannot manipulate cursor outside of render phase, only
> om.core/transact!, om.core/update!, and cljs.core/deref operations allowed".
>
>
>
> when I start to edit the field.
>
>
>
> So I thought I needed to deref the entry in init-state, but sadly om says
> that's not allowed in the render phase. (at least I now know that init is
> part of the render phase...)
>
>
>
> So, it seems I'm not understanding something here... I'm new to clojure and
> om/react. Can someone give me some way to better understand what's going on?
> Is my sketch a useful way of thinking about this in om, or do I need to look
> at this from a different angle?
>
>
>
>
>
>
>
>
> Thanks for any help, pointers new ways of doing this,
>
>
>
> Mathias
>
>
>
> --
>
> 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.