Hi,
So I understand reagent won't re-render a component if its state is equal to
the last rendering.
I also understand that inline fns (e.g. (fn [] ...) or #(...)) are never equal.
I also understand that IE11 is just a pig.
Therefore, if you have a component whose state includes an inline on-change
handler (as seen in almost all documentation!) it will always be re-rendered.
The problem is that this is causing a trivial select box in IE11 to be redrawn
every time the parent state changes, and as it follows the clock it regenerates
every second.
In every other browser this is fine, but in IE11 sometimes clicking on an
option works sometimes it doesn't.
If I move the on-change handler to a declared (defn) then the problem goes away.
The trouble is that I have some generic 'form' infrastructure which takes a map
of all form-values and a sequence of actual hiccup form items:
(def values {:elem-1 "hi" :elem-2 "there"})
(defonce form-state (ratom/atom values))
(my-funky-form-macro {:state form-state :validation-report ....}
[form/text {:id elem-1}]
[form/text {:id elem-2}])
this is called every second but the state passed to form/text doesn't actually
change.
What my-funky-form-macro does though is assoc into each of the child items's {}
and adds an on-change handler which #(swap! state assoc {:id m} %).
It is a macro, so I can do some really funky things, but the fact is I can't
generate a stable on-change handler.
If, in my macro I wrap a (let [on-change# #(swap! state assoc {:id m} %)])
around each child on-change code and (assoc m :on-change on-change#) then it
still won't work as that 'let' is regenerated every second.
Same problem if I move it out to a top level 'let'.
The only thing I can think, to get a stable on-change handler is to actually
define one (defonce on-change-for-id-~(:id m) [event]
(swap! state assoc ~(:id m) (event->value event))
for each element. 'defonce' will be true to form and preserve the existing
on-change-for-id-~(:id m) if it already exists.
There will be one top level defonce for each unique id in the set of elements,
so it isn't bounded and there isn't that many of them.
But sheesh - really? I mean, REALLY!?
I must be being a numpty somewhere along the line as the number of advanced
macro hoops I need to jump through is insane!
And, to repeat, this is only an issue in IE11 :-()
What have I missed?
(ignore my stupid macro syntax mistakes).
--
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 https://groups.google.com/group/clojurescript.