Fork me on GitHub
#re-frame
<
2017-05-19
>
seantempesta06:05:57

Is there a way to prevent subscriptions from re-run’ing if they haven’t changed? Like component A is always deref’ing subscription B (which is expensive to run). If component A could just get the value from the last run that’d be great.

seantempesta06:05:40

Subscription B isn’t using the app-db. Just another subscription.

seantempesta06:05:07

Ah, never mind! I just needed to use reg-sub-raw and not deref the app-db. Sorry for the noise! 🙂

cmal09:05:30

code is here:

(re-frame/reg-event-db
 :execute
 (fn [db [_ input-val]]
   #_(re-frame/dispatch [::http-get (str conf/execution-url "?token=" conf/token "&statement=" input-val)])
   (re-frame/dispatch [::http-get ""])))

(re-frame/reg-event-fx
 ::http-get
 (fn [db [_ url]]
   {:http-xhrio {:method          :post
                 :uri             url
                 :timeout         5000
                 :format          (ajax/json-request-format)
                 :response-format (ajax/json-response-format {:keywords? true})
                 :on-success      [::good-post-result]
                 :on-failure      [::bad-post-result]}}))

thegeez09:05:04

@cmal that is a problem with CORS (Cross-Origin Resource Sharing), you're making a request from one domain to another and you need to properly use CORS to allow that. This is a not problem specific to re-frame

cmal09:05:31

I just worked through the CORS problem

cmal09:05:32

That is another problem. I've met the CORS problem and I will post the error of it.

cmal10:05:36

@thegeez If the first 404 error is also a CORS problem, can you tell me how to bypass it? I am using figwheel and maybe I should make the request host to be localhost:3449. Thank you.

thegeez10:05:01

There is no bypass for CORS requests, the endpoint needs to properly implement CORS and allow CORS requests for this to work. This is not related to re-frame or figwheel or other tooling on your front-end.

cmal10:05:51

If setting the headers in my localhost:6787 server to ALLOW ALL cannot solve the CORS problem, I thought maybe figwheel could use something like ring-proxy to proxy some url to local path. I tried to do that but the source code of figwheel are too hard for me and the ring-proxy cannot work as I expected.

cmal10:05:58

Are there any other tooling on front end could let me request an API from other hostname?

kamituel11:05:33

Hey! todo-mvc example shows one way on how to validate app-db against schema. Is there any canonical way of validating (1) payloads of (dispatch …) calls (2) return values from sub handlers? I guess a “before” interceptor for event handlers could somewhat solve (1). Any better way? How about (2)?

bradleesand16:05:19

@kamituel you could use schema or clojure.spec with :pre and :post conditions on your subs and event handler fns like shown here: https://clojure.org/guides/spec#_using_spec_for_validation

owen16:05:11

alternatively you could spec your entire @db and have it run as an after for events

bradleesand17:05:09

^ this is what I do

bradleesand17:05:25

only in dev, not prod

kamituel17:05:51

I’m doing that for DB too, but it’d be great to have it for results of sub handlers too.

kamituel17:05:16

I guess :pre/:post could work. Is there a ClojureScript equivalent of https://github.com/jeaye/orchestra?

kamituel17:05:38

(might be a noob question, but we’ve only very recently upgraded to 1.9 so spec is kinda new to me)

owen19:05:50

I don't know I havent seen that project, might be a better question for #clojure-spec