Skip to content

Instantly share code, notes, and snippets.

@fredyr
Created January 21, 2014 09:43
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fredyr/8537199 to your computer and use it in GitHub Desktop.
Save fredyr/8537199 to your computer and use it in GitHub Desktop.
Removing a table row failed in om/react when tbody was missing.
(ns om-table.core
(:require [om.core :as om :include-macros true]
[om.dom :as dom :include-macros true]))
(enable-console-print!)
(extend-type string
ICloneable
(-clone [n] (js/String. n)))
(def app-state (atom {:table ["very" "undefined" "such" "parentNode"]}))
(defn table-row [text owner]
(prn text)
(om/component
(dom/tr nil
(dom/td nil (om/value text)))))
(defn table-test [rows owner]
(om/component
(dom/table
nil
;; the code breaks if tbody is omitted, since this node is
;; implicitly inserted by the browser if missing, causing the
;; react diff (or otherwise inside of react) to throw an error
(dom/tbody nil
(om/build-all table-row rows)))))
(defn remove-first [rows]
(om/update! rows
#(into [] (drop 1 %))))
(om/root
app-state
(fn [{:keys [table]} owner]
(reify
om/IRender
(render [_]
(dom/div nil
(om/build table-test table)
(dom/button #js {:onClick #(remove-first table)} "Remove")))))
(.getElementById js/document "content"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment