Closed jimpil closed 12 months ago
FYI, i solved my problem by pushing the subscriptions deeper (i.e. closer to their respective consumers), like this:
(defn unit-typeahead
[{:keys [base-unit choices]}]
(let [current-base-unit @(rf/subscribe [::subs/current-base-unit])
base (or current-base-unit base-unit)]
[rc/typeahead
:src (at)
:suggestion-to-string get-label ;; won't accept keyword
:render-suggestion get-label ;; is documented to accept 2 args
:change-on-blur? true ;; is documented to default to true
:model {:id base :label (name base)} ;; is documented to be optional
:data-source (partial suggest-from choices)
:debounce-delay 200
:on-change #(rf/dispatch [::events/base-unit-selected (:id %)])]))
(defn unit-amount []
(let [current-n @(rf/subscribe [::subs/current-n])
n (or current-n 1)]
[rc/input-text
:src (at)
:model (str n)
:on-change #(rf/dispatch [::events/n-selected (parse-double (str/trim %))])]))
which lets me write my original component like so:
[rc/h-box
:src (at)
:gap "1em"
:children [[unit-typeahead quantity]
[unit-amount]]]
I'm still not sure what was wrong before, but I guess it's good practice to do that anyway, so I'm happy.
Hi there,
I seem to be having the strangest issue with the following simple component. I've spent several hours looking at this, and I've reached a point where I fairly certain that I'm doing everything correctly. Ok so imagine the following component:
The
typeahead
component works perfectly in isolation (despite being incorrectly documented in various places - see comments on the snippet above). However, when a value is selected on theinput-text
, the typeahead loses its selection! I've included the relevant events/subscriptions in the snippet as proof that::events/n-selected
doesn't do anything unusual. In fact, I have console-logs andre-frisk
telling me that no value has been lost from the db, so I am at a complete loss here - mainly because i spent quite a bit of time to make thetypeahead
work (the outdated docs didn't help there), and now this happens from a different/completely-unrelated component!If you can provide any hints or clues, that would greatly appreciated! Many thanks in advance...