Created
January 9, 2016 12:16
-
-
Save geraldodev/f926685132e306663487 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(def init-data {:clientes [{:id 1 | |
:nome "geraldo" | |
:versao 0} | |
{:id 2 | |
:nome "luiz" | |
:versao 1}] | |
:form-cliente {:id 1 | |
:nome "geraldo" | |
:versao 0}}) | |
(defmethod read :form-cliente | |
[{:keys [state]} key params] | |
(let [st @state | |
key-v (get st key) | |
r (when (vector? key-v) (get-in st key-v)) | |
_ (prn "key-v" key-v)] | |
{:value (or r {} ;; {:id "100" :nome "astrogildo" :versao "100"} | |
)})) | |
(defmethod mutate 'app/limpa-form-cliente | |
[{:keys [state]} _ _] | |
(prn "entrou limpa-formcliente") | |
{:value {:keys [:form-cliente]} | |
:action (fn [] | |
(prn "action from limpa-formcliente") | |
(swap! state assoc :form-cliente [:cliente/by-id -10000]) | |
;; (swap! state assoc :form-cliente [:cliente/by-id 2]) | |
(prn "result do swap" @state))}) | |
(defmethod read :clientes | |
[{:keys [state]} k p] | |
(let [st @state] | |
{:value (into [] (map #(get-in st %)) (get st :clientes))})) | |
(defui CreditoApp | |
static om/IQuery | |
(query [this] | |
(let [q-cliente (om/get-query Cliente)] | |
`[{:form-cliente ~q-cliente} {:clientes ~q-cliente}])) | |
static om/IQueryParams | |
(params [this] | |
{:tabela-atual nil}) | |
Object | |
(render [this] | |
(println "CreditoApp " (om/props this)) | |
(let [{:keys [form-cliente clientes]} (om/props this)] | |
(dom/div | |
nil | |
(cliente form-cliente) | |
(dom/ul nil | |
(map #(dom/li (js-obj "key" (:id %)) (:nome %)) clientes)) | |
;; (form-dinamico {:table-name "cliente" :a :form-data/cliente-a} ) | |
)))) | |
(def reconciler | |
(om/reconciler | |
{:state init-data | |
:parser (om/parser {:read read :mutate mutate}) | |
:send (util.transit/transit-post "/api/parser")})) | |
(om/add-root! reconciler | |
CreditoApp | |
(gdom/getElement "app")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment