Skip to content

Instantly share code, notes, and snippets.

@jlongster
Created February 15, 2016 17:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jlongster/757ab6be90d0643bf4a3 to your computer and use it in GitHub Desktop.
Save jlongster/757ab6be90d0643bf4a3 to your computer and use it in GitHub Desktop.
(defui TransactionRow
static om/Ident
(ident [this {:keys [id]}] [:transactions/by-id id])
static om/IQuery
(query [this] '[:id :amount :description :date :from_acct :to_acct])
Object
(render [this]
(println "rendering" (:id (om/props this)))
(let [{:keys [columns widths formatters on-edit]} (om/get-computed this)
id (:id (om/props this))
data (into {} (map (fn [c] [c (get (om/props this) c)]) columns))]
(dom/div
#js {:key id}
(map-indexed
(fn [idx [col value]]
(let [formatter (get formatters col)
text (if (and formatter value)
(formatter value)
(or value ""))]
(dom/input
#js {:key (name col)
:defaultValue text
:onBlur
#(let [value (.-value (.-target %))]
(om/transact!
this
`[(transaction/update ~(assoc {:id id} col value))]))})))
data)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment