-
Notifications
You must be signed in to change notification settings - Fork 16
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
How-to contains misleading memo use #60
Comments
I think that hx should provide a (defnc WrappedComponent [{:keys [someValue]}]
{:wrap [(some-lib/withSomeValue)
(react/memo (props= :someValue))]}
;; Return hiccup
[:div "I was rendered with " someValue]) and it would avoid doing |
The docs should also be fixed 😬 thanks for the report |
How does hx serialize the props into a Clojure data structure? Does it use |
No, it uses custom The eventual goal is to move to cljs-bean for this, and delete most of that code. To compare props, we don't want to serialize the whole props object back to a map, so it would be better to take a collection of keys as args, turn those into strings on Since We could also perhaps enumerate all keys if e.g. nothing is passed into |
That's exactly how I was using it, because 99% of my components take immutable data structures. |
@SevereOverfl0w in that case, using plain The problem I'm trying to dance around is that There are times when this might be necessary or preferred, but I don't really understand those cases yet and I don't want to setup the defaults to be a performance footgun. Reagent at first defaulted to I would rather encourage people to leverage immutable data better, where an object identity change is a good way to detect that the data contained within it has changed. FWIW a function that enumerates each key and does a deep comparison is ~5 lines of code: (defn all-props= [p p']
(let [ks (goog.object/getKeys p)
ks' (goog.object/getKeys p')]
(and (= (count ks) (count ks'))
(every #(= (goog.object/get p %) (goog.object/get p' %)) ks)))) But again, this shouldn't be necessary if you're using immutable data. Memoizing is already full of footguns and gotchas (functions passed in as event handlers, literal data created in render, etc.) that I want to make sure that I don't make it harder to reason about by defaulting to something that can have radically different performance depending on subtle things in the users application. |
Minor nit, but Reagent still uses Reaction: https://github.com/reagent-project/reagent/blob/master/src/reagent/ratom.cljs#L439 ShouldComponentUpdate: https://github.com/reagent-project/reagent/blob/master/src/reagent/impl/component.cljs#L199 In the case of Reactions, there is an The discussion that led to this: reagent-project/reagent#143 Personally I like the idea of |
the memo comparator should not be
=
but something more like(fn [x y] (= (js->clj x) (js->clj y)))
. The result ofclj->js
is what's passed to the comparator, and cljs never compares them as truthy.The text was updated successfully, but these errors were encountered: