This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-08-28
Channels
- # bangalore-clj (1)
- # beginners (67)
- # braveandtrue (179)
- # cider (28)
- # cljdoc (1)
- # clojure (132)
- # clojure-conj (3)
- # clojure-dev (1)
- # clojure-finland (6)
- # clojure-nl (2)
- # clojure-russia (6)
- # clojure-spec (19)
- # clojure-uk (62)
- # clojurescript (90)
- # clojutre (5)
- # component (2)
- # cursive (30)
- # data-science (1)
- # datomic (42)
- # duct (9)
- # emacs (1)
- # figwheel-main (158)
- # fulcro (57)
- # funcool (3)
- # hoplon (1)
- # jobs (17)
- # mount (38)
- # off-topic (15)
- # re-frame (53)
- # remote-jobs (2)
- # schema (11)
- # shadow-cljs (299)
- # spacemacs (25)
- # specter (2)
- # tools-deps (54)
- # vim (11)
- # yada (6)
is there a nice way to pass on the result of a subscription? so i could do stuff like (-> (subscribe [:a]) (subscribe [:b with-result-of-a]) (fn [[a b]] {:a a, :b b}))
@arne-clojurians to me it sounds like you want to have layer-3
subscriptions https://github.com/Day8/re-frame/blob/master/docs/SubscriptionInfographic.md The idea is that you can compose subs that extract some path from db (layer-2) into a “materialized views” (layer-3).
yes, kind of. but layer-3 subscriptions seem to work like 1. run some subscription -> 2. do something with the result of the previous computation. the problem i have is that i need a third step (see above, the subscription running with the result of the previous subscription) where i need the result of the first step as well. at the moment i'm running the first subscription twice which is ok because it's cheap, but it's not very elegant
You can subscribe to the previous step. One moment, I’ll try to make my self clear 🙂
Usually you can arrange your stuff so that you can compose your subs like this
(re-frame/reg-sub
::cats
(fn [db _]
(:cats db)))
(re-frame/reg-sub
::dogs
(fn [db _]
(:dogs db)))
(re-frame/reg-sub
::cat-ages
:<- [::cats]
(fn [cats _]
(map :age cats)))
(re-frame/reg-sub
::dog-ages
:<- [::dogs]
(fn [dogs _]
(map :age dogs)))
(re-frame/reg-sub
::total-age
:<- [::cat-ages]
:<- [::dog-ages]
(fn [[cat-ages dog-ages] _]
(reduce + (concat cat-ages dog-ages))))
And you can do artibrary computation at any of the steps and subscribe to that data in other subscriptions.
Ahhh now I read your message again and got your point. So you need earlier results further down the chain. Don’t be worried about the performance because intermediate results are cached.
And now I read it again and I’m not sure if I get what’s the problem. 🙂 But as far as I understand I think you can just split the computation into different subs and subscribe to the intermediate results wherever you need them.
Hi guys, I'm having a problem with an on-click handler, I wonder if anyone could help. Essentially I have a GDPR consent form, using signature-pad (https://github.com/szimek/signature_pad) to capture a signature. So when moving on from the form, I need to extract the signature from the signature pad and storing it in the database. I'm setting the on-click handler by setting a map including the key :on-click as the attributes of an element, and I'm logging to the console so I can see the function which sets the attributes is being called. But when I inspect the element, the on-click handler is not present, and when I click the element, nothing happens. Fuller explanation here: https://groups.google.com/forum/#!topic/clojure/D2iGl0jkaaM
Any help exceedingly welcome!
Did you wrap the on-click handler in #(…)
as needed? It sounds like the function might be called in page load rather than on click.
Yes, it's here: https://github.com/simon-brooke/youyesyet/blob/feature/reflow-app/src/cljs/youyesyet/canvasser_app/views/gdpr.cljs#L58
Hang on...
No apparent change. That might be figwheel failing to reload, hang on...
Doing a clean and rebuild, to be sure, to be sure...
H'mmm... stepping through in Javascript, it's because that's not actually being called...?!?
Is there anything magic re-frame does with the value of :on-click
keys?
never seen anything unusual, give it a function and it just calls it. It does pass in the on-click event, so maybe add that in as an arg to your handler function?
Hi, anyone had any luck with Microsoft Edge? I'm working with input elements, and need an :on-change
handler, but if I include one then typing performance is prohibitively slow, even if the handler is a no-op (It's over 300ms for each button press when I'm emulating a Surface Pro 4, which is a fairly reasonable situation for our target audience). Re-frame-10x says the timing is all "misc", so I'm a little stumped as to what's going on. Any suggestions on how to debug further?
@simon_brooke what do you mean keys? Your own ui helper function just changes :handler
key for the on-click
. Did you get rid of the doubly nested function?
OK, I'm not clear what you mean by a double nested function; I've removed the #( and subsituted just (, but that makes no difference.
(ui/big-link "I consent"
;; :target (str "#elector/" (:id elector) "/true/")
:handler (fn
[]
(ui/log-and-dispatch
[:set-consent-and-page {:elector-id (:id elector)
:page :elector
:elector (merge elector
:signature
(.toDataURL
sig-pad
"image/svg+xml"))}])))
note that there isn't a #
in front of the fn.also your merge seems kinda weird. I don't understand what the keyword :signature
is supposed to accomplish in the merge
which might explain it. (merge {} :bob :apple)
throws an error. is it possible you're throwing an error in the dispatch and not seeing it?
Yes, that's what I now have. And you're right, that merge
should be assoc
...
However, the interesting thing I've found is that if I change :on-click
to :alt
- and make no other changes, thus:
(defn big-link [text & {:keys [target handler]}] (js/console.log (str "Big link with target '" target "'; handler '" handler "'")) [:div.big-link-container {:key (gensym "big-link")} [:a.big-link (merge {} (if target {:href target}{}) (if handler {:alt handler}{})) text]])
I do get the function as alt text, but if I change it back to :on-click
, I don't get an on-click handler...
Yes, confirmed. If I use an attribute name that's invalid, like :froboz
, then no attribute is generated. If I use one that's valid but the value would just be text, I get the text of my handler. If I use :style
, things go VERY weird; and if I use :on-click
, like :froboz
, I get nothing...
*OH WAIT*
OK, so this doesn't work either:
(ui/big-link "I consent" :handler #(ui/log-and-dispatch [:set-consent-and-page {:elector-id (:id elector) :page :elector :elector (assoc elector :signature (.toDataURL sig-pad "image/svg+xml") )}]))
(which is presumably the other solution to what you meant by 'double wrapped function').
:onclick
also results in nothing...
one thing i would recommend is not use big-link. just use a simple structure and get it going. then you can diagnose if there's an issue with biglink or your handler
Yes, that-s a good suggestion.
OK, so what I currently have is this:
(defn gdpr-render [] (let [elector @(subscribe [:elector])] [:div [:h1 "I, " (:name elector)] [:div.container {:id "main-container"} [:table [:tbody [:tr [:td [:p "Consent to have data about my voting intention stored by " [:b "Project Hope"] " for use in the current referendum campaign, after which it will be anonymised or deleted."] [:p [:i "If you do not consent, we will store your voting intention only against your electoral district, and not link it to you"]]]] [:tr [:td [:canvas {:id "signature-pad"}]]]]]] (ui/back-link "#dwelling") [:div.big-link-container {:key (gensym "big-link")} [:a.big-link {:on-click #(ui/log-and-dispatch [:set-consent-and-page {:elector-id (:id elector) :page :elector :elector (assoc elector :signature (.toDataURL sig-pad "image/svg+xml") )}])} "I consent"]] (ui/big-link "I DO NOT consent" :target (str "#elector/" (:id elector) "/false"))]))
No on-click handler is generated, either using the key :on-click
or the key :onclick
.
Tried :onClick
as well, nothing.
It also makes no difference if I change from an a
tag to a span
tag: still no on-click handler with any of :on-click
, :onclick
or :onClick
Right, on another page I use :on-click
, no 'on-click' attribute shows in the element which you inspect it, but nevertheless the value of the :on-click
key is called when the element is clicked. So I think someone's suggestion upthread that my function is being called but is failing silently is probably right....
Yes, that's correct. When I try [:a.big-link {:on-click #(js/console.log "Hello there") "Froboz"]
I get Hello there
in the console.
Thanks everyone, I'm cooking with gas now.
In the docs here https://github.com/Day8/re-frame/blob/master/docs/API.md#built-in-effect-handlers, there's an ambiguity (in my head at least) in the explanation of :dispatch-later
. When I return the following from an fx handler:
{:dispatch-later [{:ms 200 :dispatch [:foo]}
{:ms 100 :dispatch [:bar]}]}
Does [:foo]
get dispatched at t+200ms and [:bar]
at t+300ms. Or does [:bar]
get dispatched first?