This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-07-18
Channels
- # announcements (35)
- # babashka (14)
- # beginners (23)
- # calva (5)
- # cljsrn (3)
- # clojure (154)
- # clojure-europe (12)
- # clojure-losangeles (2)
- # clojure-uk (5)
- # clojurescript (42)
- # conjure (3)
- # cursive (10)
- # datomic (3)
- # emacs (6)
- # events (1)
- # graalvm (1)
- # helix (1)
- # honeysql (1)
- # hyperfiddle (1)
- # jobs-discuss (1)
- # lsp (8)
- # malli (54)
- # meander (1)
- # membrane (1)
- # off-topic (246)
- # polylith (4)
- # practicalli (1)
- # re-frame (14)
- # releases (1)
- # shadow-cljs (21)
- # sql (58)
- # vim (1)
- # vrac (2)
(rf/reg-event-fx
:filter
(fn [{:keys [db]} _]
{:http-xhrio {:method :get
:uri ""
:params {:request @(rf/subscribe [:request])
:constraints @(rf/subscribe [:constraints])}
:response-format (ajax/json-response-format {:keywords? true})
:on-success [:success-http-result]
:on-failure [:failure-http-result]}}))
Hello, I have a event that makes a database call as shown. I believe there are issues with what I am doing in the :params
. May I know what should I be doing instead of :constraints @(rf/subscribe [:constraints])}
? Do I need to write it as json first? Am thinking I am doing something wrong as it seems my constraints map in the re-frame db ...
[{:name "Land Take"
:constraint :land-take
:details {:min "100", :max "500"}}
{:name "Total GFA"
:constraint :land-gfa
:details {:min "100", :max "500"}}]
seems to be passed as
{:name ["Land Take" "Total GFA"]
:constraint ["land-take" "total-gfa"]
:details {:min ["100" "100"], :max ["500" "1000"]}}
First of all, don't use subscribe
inside event handlers: http://day8.github.io/re-frame/FAQs/UseASubscriptionInAnEventHandler/
Second of all, IIRC :params
is a map which for :get
requests without any request format will be converted into query parameters, so the values there must be plain scalars, like numbers, strings, etc.
Ah, my bad - seems like the values can be vectors. By default, {:a [1 2]}
will be converted into a=1&a=2
.
I simply wouldn't use subscriptions there at all. Just extract the values from the db
directly.
I have no idea what you mean by that. Given the DB above, what query string do you want to get?
{:constraints [{:name "Land Take"
:constraint :land-take
:details {:min "100", :max "500"}}
{:name "Total GFA"
:constraint :land-gfa
:details {:min "100", :max "500"}}]
:request nil}
My db is like this? I want both :constraints
and :request
I don't quite understand what you mean by "Just extract the values from the db directly"I was trying to ask if you mean for me to pass the data to the my filter event like {:filter request constraints]
I was hoping there would be a way to translate :constraints
as it is, like
[{:name "Land Take"
:constraint :land-take
:details {:min "100", :max "500"}}
{:name "Total GFA"
:constraint :land-gfa
:details {:min "100", :max "500"}}]
or a way for me to perhaps write
to json and read
such that my backend receives the data such a format