ckirkendall / kioo

Enlive/Enfocus style templating for Facebook's React and Om in ClojureScript.
Eclipse Public License 1.0
403 stars 39 forks source link

Om cursors? #23

Closed terhechte closed 10 years ago

terhechte commented 10 years ago

Given the following example:

(defsnippet my-header "main2.html" [:header]
  [{:keys [points] :as data}]
  {[:h1] (content points)
    [:h1] (listen :on-click (fn [e] (om/transact! data :points inc))})

(deftemplate my-page "main2.html"
  [data]
  {[:header] (substitute (my-header data))})

I'm using kioo with Om, and in Om all application state is being shared via Om cursors. I would have expected that the template / snippet local state thus would be cursors, too. But instead they seem to be normal Clojure data structures, as I'm getting the following error when trying to do use transact on the data (as in the example, clicking the h1):

Uncaught Error: No protocol method ITransact.-transact! defined for type cljs.core/PersistentHashMap: 

Is there a setting I need to define to get cursors, or how would I get the appropriate cursor in the snippets / templates? I'm sorry if I misunderstood something obvious :)

Cheers & Thanks, Benedikt

ckirkendall commented 10 years ago

Kioo doesn't do anything to the args pass in so this is going to need a bit more investigation. Can you post a gist or github repo that reproduces the issue. Below is the base code of snippet. You can see it doesn't touch the args coming in. Note: check-val? is passed in as false if you are using the om namespace.

(defn snippet*
  ([path body args emit-opts]
     (snippet* path body args emit-opts false))
  ([path body args emit-opts check-val?]
     (if check-val?
       `(kioo.core/value-component
         (fn ~args
           ~(component* path body emit-opts)))
       `(fn ~args
          ~(component* path body emit-opts)))))
terhechte commented 10 years ago

Sorry for this. I found the issue, somehow my app-state map had the relevant data as a list instead of a vector and it seems that this case is not correctly processed by Om. After enclosing it in (vec ..) everything was fine.