Created
January 21, 2014 09:43
-
-
Save fredyr/8537199 to your computer and use it in GitHub Desktop.
Removing a table row failed in om/react when tbody was missing.
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
(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