As far as I know there are two steps to dom modification in Om: 1. Rendering to the virtual dom - this happens only when app state or component local state changes, so if you're careful about modifying state, you can control when components are rendered. You can also use IShouldUpdate for fine grained control over when a component is updated and rendered. For example, take a look here to see how to prevent specific state changes from triggering a rerender: https://github.com/swannodette/om/issues/134#issuecomment-41954161 2. Rendering the virtual dom to the real dom - this is done by React and is only done for DOM nodes that have actually changed between renders. That is, if Om renders a something that is identical to what it was before, then React will not render it into the real DOM. Ie the virtual DOM is diffed with the previous version to create a minimal set of changes.
As far as I can see, there is no way to actually tell how many changes are actually committed to the real dom. You can manually count how many times render is called, but there is no way of knowing what React does with the output - at least, not from Om. Maybe its possible by accessing the React objects directly, but I have no experience with that. On 17 May 2014 11:21, Juan Manuel Gimeno Illa <[email protected]> wrote: > Is there a way to know the number of modifications of the dom emited by om > when rendering? > > I've make an snake game based on om and I wonder if om only modifies the > two cells (head and tail) at each movement or repaints the whole world at > each step. > > The two relevant components are: > > (defn cell [[[x y] type] _] > (reify > om/IRender > (render [_] > (dom/rect #js {:x (* x size) :y (* y size) :height size :width size > :className type})))) > > (defn world [{:keys [food snake dead]} _] > (reify > om/IRender > (render [_] > (let [foodcell [food "food"] > snakestyle (if dead "dead" "alive") > snakecells (map #(vector % snakestyle) snake) > allcells (cons foodcell snakecells)] > (apply dom/svg #js {:width (* width size) :height (* height size)} > (om/build-all cell allcells)))))) > > The project is at https://github.com/jmgimeno/om-snake > > Thanks! > > -- > Note that posts from new members are moderated - please be patient with > your first post. > --- > You received this message because you are subscribed to the Google Groups > "ClojureScript" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at http://groups.google.com/group/clojurescript. > -- Note that posts from new members are moderated - please be patient with your first post. --- You received this message because you are subscribed to the Google Groups "ClojureScript" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/clojurescript.
