Fork me on GitHub

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.


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


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


code is here:

 (fn [db [_ input-val]]
   #_(re-frame/dispatch [::http-get (str conf/execution-url "?token=" conf/token "&statement=" input-val)])
   (re-frame/dispatch [::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]}}))


@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


I just worked through the CORS problem


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


@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.


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.


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.


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


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)?


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


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


^ this is what I do


only in dev, not prod


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


I guess :pre/:post could work. Is there a ClojureScript equivalent of


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


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