O'Reilly logo

Learning ClojureScript by Allen Rohner, Rafik Naccache, W. David Jarvis

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Determining the size of a component

As an Om neophyte, you might be wondering what the difference is between building subcomponents and just regular functions that return HTML. Let's look at a hypothetical choice borrowed from our previous todo list example:

(defn todo-item [cursor owner] 
  (dom/div nil 
    (dom/span #js {:className (when (:done? cursor) 
                                "done")} 
      (:text )))))cursor)))) 
  
(defn todo-list  [cursor owner] 
  (reify om/IRender 
    (render [_] 
      (dom/div nil 
        (dom/h1 nil (:text cursor))  
        (dom/div nil 
                       (for [t (:todos cursor)] 
                          (todo-item t owner))))))) ``` 

This is a slightly modified version of our previous todo application. Here, todo-item is a standard function that happens to return virtual DOM nodes rather than an Om component constructor. It doesn't ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required