Hi,
I am trying to use om-sync to update my server when something in my app state
changes. But, whenever I do that I only send one key of my whole map to the
server, which is useless as some metainformation such as an unique id is
missing.
I put together a small working example which shows exactly this problem. You
can copy this into a file and after clicking a button you will see that the put
request sends only a map with one key:
(ns om-async.core
(:require-macros [cljs.core.async.macros :refer [go]])
(:require [cljs.core.async :as async :refer [put! chan alts!]]
[goog.dom :as gdom]
[om.core :as om :include-macros true]
[om.dom :as dom :include-macros true]
[om-sync.core :refer [om-sync]]
[om-sync.util :refer [tx-tag edn-xhr]]
[cljs-time.core :as cljs-time]
[cljs-time.format :as cljs-format]))
(def test-state (atom {:releases {:url "/releases" :coll [{:keyone "testvalue"
:keytwo "testval2"} {:keyone "testvalmap2" :keytwo "tesval2map2"}]}}))
(defn test-view-deeper [app owner]
(reify
om/IRenderState
(render-state [_ _]
(apply dom/div nil
(map #(dom/button
#js {:onClick (fn [e] (println "clicked button")
(om/transact! % :keyone (fn [_]
"newtestval") :update))}
(:keyone %)) app)))))
(defn test-view [app owner]
(reify
om/IRenderState
(render-state [_ _]
(dom/div nil
(om/build om-sync (:releases app)
{:opts {:view test-view-deeper
:filter (comp #{:create :update :delete}
tx-tag)
:id-key :class/id
:on-success (fn [res tx-data] (println
"success " res))
:on-error
(fn [err tx-data]
(println "error "))}})))))
(let [tx-chan (chan)
tx-pub-chan (async/pub tx-chan (fn [_] :txs))]
(om/root test-view test-state
{:target (gdom/getElement "test")
:shared {:tx-chan tx-pub-chan}
:tx-listen (fn [tx-data root-cursor]
(put! tx-chan [tx-data root-cursor]))}))
The put request in chrome looks like this:
Request payload: {:keyone "newtestval"}
Any Ideas what is wrong here? And how to do it right?
Best Regards,
Sven
--
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.