Om, the clojurescript React shell, is considered very fast because it uses immutability. I can't figure out how persistent data structures can help here.
I realized that the state of the application is an atom. This state is passed to the functions (om components) that the virtual DOM nodes return, so creating a βpatchβ of the differences between the current virtual DOM and its previous state is much better than working directly with the actual DOM.
But where can persistent data structures be stored?
(def app-state (atom {:foo {:counter 0})) (om/root click-counter app-state {:target ...})
for example, click-counter display a button that, when clicked, increments the counter. So the transition function is as follows:
(dom/button #js {:onClick #(om/transact! app [:foo :counter] inc)} (str "clicked " (-> app :foo :counter) " times"))
I found this: when executing onClick clojurescript creates a new map (very efficiently) as follows:
{:foo {:counter 1}}
and app-state now points to a new mapping. At this point, Om realizes that the state is changed because it is just a matter of checking equality.
The problem here is that Om should still calculate the difference between the whole old virtual DOM and the new one. He does not know that only the counter is changed.
Where is my mistake?
agori source share