-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Why identical? instead of = for value comparisons? #43
Comments
Hi Dave, so yes, |
As often happens, filing an issue got me thinking more deeply about my problem. We're making HTML custom elements based on freactive and Datascript. I had built some lenses to abstract Datascript and provide an entity map based on entity IDs. When the Datascript instance changed due to user input, the entity cursor sent a notification even though the entity itself hadn't changed, and that propagated to cause the spurious re-render. By restructuring how the model data propagates to the custom elements, I was able to solve the problem. And the code is clearer now anyway, has better decoupling, etc. The other case I'm using is lenses based on Datascript queries, where it would be nice to do a set equality to see if the result actually changed. But really, it's a special case, and probably deserves a custom implementation of the relevant protocols rather than expecting the generic implementation to handle it. So I'm going to agree that the default implementation uses I do think the DOM equality check you suggested might be handy. I have run into cases where I use something like |
I changed the DOM equality check to use Let me know how this affects things on your end. Also, FYI in the HEAD of the develop branch there is a completely new cursor (and atom) implementation - should be much more powerful and works in my test, but if you get a chance to try please let me know if you run into any issues. |
Not sure this is working as you planned. Here's the code I used to test: (ns freactive-sandbox.rx-test
(:require-macros [freactive.macros :refer [rx debug-rx]])
(:require [freactive.core :refer [atom cursor]]
[freactive.dom :as dom]))
(enable-console-print!)
(def state (atom {:a 1 :b {:c 2 :d 3}}))
(def b (cursor state :b))
(defn view
[]
(let [a (cursor state :a)
cd (cursor b #(* (:c %) (:d %)) #())]
(rx
(println "A" @a)
[:div (str @a)
[:div
#_(println "BBBBB" @b)
[:div (rx (str @b))]
(rx (println "B" @b)
[:div (str "c*d " @cd)])]])))
(dom/mount! (.getElementById js/document "root") (view))
(reset! b {:c 4 :d 5})
(js/setTimeout #(reset! b {:c 5 :d 4}) 100) I added some
I fiddled around with
Compare last four lines: is this more what we should expect? Haven't played a great deal with the new atom/cursor implementations. I'm about to start converting another big chunk of our application from a custom virtual-DOM-based implementation to cereus and freactive, so that should be a good test. Also, the code above used to recompute the top-level |
Can you post your before and after code for show-new-elem and animate? Are
|
Here's the diff: I am using develop HEAD. |
You're right - the way I had it I was comparing the DOM node itself to the |
I've run into times when an
rx
expression is updated even though it's value (and the value of it's dependencies) are the same, resulting in brief flashes because the corresponding piece of DOM re-renders. Looking at the code, I'm guessing this is becauseidentical?
is used instead of=
when determining whether to notify watches. Is there a reason for this? If it's for performance, could it be made configurable?The text was updated successfully, but these errors were encountered: