Fork me on GitHub
#clojurescript
<
2018-01-17
>
ag00:01:05

how can I restrict lein doo to run tests only in a given ns?

ag00:01:27

easily I mean (without modifying configs)

rauh08:01:45

@ajs Like what kind of string literals? Used how?

Alex Miller (Clojure team)08:01:26

I have painfully learned that if I see an impossible thing happening, the most likely cause is that I’m assuming something that isn’t true. maybe worth double-checking that the code you’re looking at is the code you’re running and that however you are searching the advanced code, you’re not finding it for some unrelated reason (encoding, case, line breaks, etc).

ajs08:01:20

in an advanced build, there should only be one source file at the end with all my compiled code, is that right? I can search within this file and see several string literals that are actually in my cljs code base, but also cannot find several that are in fact in the code base, and appearing onscreen, but not in the file. Simple strings like (some-function “Hello There”) — shouldn’t I expect to see “Hello There” in the compiled code?

ajs08:01:04

everything is working fine, I’m just curious why the literals are not visible in the compiled code and yet they are clearly there and working

jakob08:01:40

I am trying to figure out how phrase function works in https://github.com/alexanderkiel/phrase . There is very limited documentation. I would love to see an example. Also API docs to phrase-all would be nice. I want to validate many field at once and looking for how to do it the best way. I guess that is a pretty common use case. I am happy to contribute to docs once I figure out how to do it 🙂 cc. @akiel

akiel08:01:02

@karl.jakob.lind There is no phrase-all function. In the README I explain why. I have a spec for each form field and print only the first problem using phrase-first. Can you please show me the spec and some example invalid values, you like to use?

jakob09:01:30

I have a spec that looks like this:

(s/def ::required-string (s/and string? not-empty))
(s/def ::name ::required-string)
(s/def ::phone (s/and string? #(re-matches #"(\+47)?\d+" %)))
(s/def ::email (s/and string? #(re-matches #".+@.+" %)))
(s/def ::first-name ::name)
(s/def ::last-name ::name)
(s/def ::orderer (s/keys :req-un [::first-name ::last-name ::email ::phone]))
Some example invalid data:
{
 :first-name "asdf"
 :last-name "hello"
 :email "asdf"  ;email must contain @
 :phone "hello" ; phone must be numbers
 }
{
:first-name "" ; cannot be empty
:last-name "" ; cannot be empty
:email "" ; cannot be empty
:phone "" ; cannot be empty
}

akiel09:01:26

Okay. I see. You like to validate the whole map at once. You can do that by calling phrase on the individual problems. Given:

(defphraser #(re-matches _ %) {:via [::phone]} [_ _] "Invalid phone number.")

(defphraser #(re-matches _ %) {:via [::email]} [_ _] "Invalid email.")
Call the following:
(map #(phrase nil %) (::s/problems (s/explain-data ::orderer {:first-name "asdf" :last-name "hello" :email "asdf" :phone "hello"})))
it returns:
("Invalid email." "Invalid phone number.")

jakob11:01:44

thanks @akiel ! it works great. Now I need the result on this format:

{
:first-name nil
:last-name nil
:email "Invalid email" 
:phone "Invalid phone number." 
}
Not sure what is the best way to achieve that. any ideas?

qqq13:01:33

@karl.jakob.lind: I don't understand what you are trying to do. Something involving specs, invalid data, and the output format of s/explain ?

gfredericks13:01:12

does anybody else have trouble finding a list of recent releases of cljs on github via their tags list?

gfredericks13:01:50

e.g., the r1.9.946 tag doesn't show up on their list for me at all, while this page suggests pretty strongly that it exists: https://github.com/clojure/clojurescript/commit/85b882b728984734793d635c923bfab0f71ba00f

rauh13:01:51

@gfredericks The front page of http://clojurescript.org links to the changes.md file

jakob10:01:04

awesome! it works flawlessly! 😄 thanks!

mfikes15:01:06

@gfredericks It is as if GitHub truncates the tags list to around 100 tags

gfredericks15:01:48

100 ought to be enough for anybody

akiel15:01:25

nobody needs more than 640kb 😉

mfikes16:01:41

GitHub’s behavior is consistent with this program: (take 4 (reverse (sort ["r3308" "v1.8" "v1.9" "r3297" "r1.9.946"])))

mfikes16:01:15

It is a bit unfortunate that all of ClojureScript’s recent tags sort as being older than the existing rNNNN tags.

josh_tackett16:01:06

I am getting the following response from my frontend server:

:status 0, :success false, :body "", :headers {}, :trace-redirects ["" ""], :error-code :http-error, :error-text " [0]"}
but I see my backend server processing and returning the correct response. I am using composure and [cljs-http.client :as http] What am I doing wrong?

justinlee16:01:13

what are you using to make the call on the frontend?

josh_tackett17:01:41

code looks like this:

(ns stock_app.requests
  (:require [cljs-http.client :as http]
            [cljs.core.async :refer [<!]])
  (:require-macros [cljs.core.async.macros :refer [go]]))


(defn make-remote-call [endpoint]
  (go (let [response (<! (http/get endpoint))]
        ;;enjoy your data
        (prn "Response : " response)
        (:body response))))

(defn test
  []
  (prn (make-remote-call (str "")))
(make-remote-call (str "")))

justinlee17:01:38

are you calling that test function? because remember that make-remote-call now returns a channel

justinlee17:01:57

although I take that back because it’s weird you are actually getting a response with status = 0

josh_tackett17:01:48

ya I see the request making it to the backend, but the response is the issue

josh_tackett17:01:01

the backend completes successfully, but there is nothing on the frontend

josh_tackett17:01:45

(defroutes app-routes

  (GET "/" []
       {:status 200
        :body "TEST"})

  (route/not-found "Not Found"))


(def app
  (wrap-defaults app-routes site-defaults))

josh_tackett17:01:54

That's the routes on the backend @lee.justin.m ^^^

justinlee17:01:37

is the logging output coming from the prn in make-remote-call or in test? I’m just trying to eliminate the possibility that you failed to wait on a channel somewhere

justinlee17:01:31

I really can’t understand how you are getting a response that looks like a cljs-http response but has status = 0

josh_tackett17:01:12

logging is showing in both

josh_tackett17:01:07

prn in test -> #object[cljs.core.async.impl.channels.ManyToManyChannel] prn in make-remote-call -> {:status 0, :success false, :body "", :headers {}, :trace-redirects ["" ""], :error-code :http-error, :error-text " [0]"}

justinlee17:01:18

okay that seems as expected. try pointing the code to a public website mabye? see if it is on the backend or the frontend

josh_tackett17:01:45

{:status 0, :success false, :body "", :headers {}, :trace-redirects ["" ""], :error-code :http-error, :error-text " [0]"}

justinlee17:01:54

okay yea i’m getting the same thing. i’m super confused why it is returning status 0. let me investigate cause i’m curious

josh_tackett17:01:57

Should we put this back in the big channel?

josh_tackett17:01:56

@lee.justin.m Let me know what you find out. I'm a bit stuck right now

justinlee17:01:01

well so far what I can tell is that if you fail a preflight check you get that weird response back. do you have authentication anywhere in your page?

justinlee17:01:49

@josh_tackett I’m not sure where to go from here. I was surprised by the status 0 responses from cljs-http but I see there are a number of ways you can get that response. I think your problem is on the backend but I use node on the backend so I’ll have to let someone else help.

justinlee17:01:45

sorry try one more thing: hit this url http://api.icndb.com/jokes/22

justinlee17:01:09

^^ @josh_tackett that url will actually return a status 200 without redirecting to https

justinlee17:01:40

you should get Response: {:status 200, :success true, :body {:type NoSuchQuoteException, :value No quote with id=22.}, :headers {content-type application/json}, :trace-redirects [ ], :error-code :no-error, :error-text }

justinlee17:01:01

and then the second thing to do: run curl -v

justinlee18:01:05

@josh_tackett did any of that help?

josh_tackett19:01:50

@lee.justin.m Sorry had to go to a meeting, same issue: {:status 0, :success false, :body "", :headers {}, :trace-redirects ["" ""], :error-code :http-error, :error-text " [0]"}

josh_tackett19:01:31

@lee.justin.m also the curl to local gives a 200

justinlee19:01:08

Okay so problem is actually client side

justinlee19:01:55

That jokes url should have given a 200

p-himik17:01:17

Is :global-exports supposed to work for the optimized build? E.g. for :global-exports {react-tagsinput ReactTagsInput} I can see my_ns.global$module$react_tagsinput = goog.global.ReactTagsInput in the output files, but I don't see any mention of ReactTagsInput in the optimized file apart from the ones created by react-tagsinput library itself.

justinlee17:01:49

@josh_tackett I’m not sure where to go from here. I was surprised by the status 0 responses from cljs-http but I see there are a number of ways you can get that response. I think your problem is on the backend but I use node on the backend so I’ll have to let someone else help.

josh_tackett17:01:25

@lee.justin.m Thank you Maybe someone else can solve this one? See thread ^^^

joshkh19:01:33

i get the impression that folks tend to favor cljs-ajax, perhaps because it's a bit simpler than cljs-http (fail / success functions rather than channels). but how do you handle race conditions using cljs-ajax? if one was to fire off two login requests back-to-back, how can you guarantee their order? using cljs-http i would store the channel from the previous request and close it first.

tomaas19:01:06

Hi, how to pass :key i? I don't want to do (into [:div] (fn[])) due to extra div? Want to be able to generate re-com elements.

tomaas19:01:22

^{:key i} this does the job

tomaas19:01:34

I suppose it's ok then

ag19:01:53

do you guys have this problem that is driving me nuts? I'm using binaryage/devtools, If I enable Custom Formatters in Chrome Dev Tools, typing things in the console becomes so annoyingly laggy 😞

ajs20:01:01

@ag I'm using devtools also but do not have that issue. I don't type directly into the console much though, but just tried and it was fast

ag21:01:52

so I can't figure out what it makes it laggy. I disable custom formatters - it works fine. I enable the setting - it becomes laggy

ag21:01:57

drives me nuts

ag22:01:08

oh, I just tried in Incognito mode. It works fine... that means that one of the extensions I have screwing things over. I was wrong, it's still happening

josh_tackett20:01:16

@joshkh I tried clj-ajax and now the response is making it back to the frontend, but then the process stops. Do you have an example of how to make the ajax request then realize the value and display?

Alex H20:01:32

so what do people think about structuring the directories as src/{cljs,clj,cljc}/foo/bar vs src/foo/bar/*.clj{s,c,}? It seems most boilerplates pick the former, but I found it slightly awkward in that the macros for a given thing end up in a very different directory

mfikes20:01:20

@alex340 I prefer the latter, as it seems simpler to me. Along the same lines as the rationale you gave, I also like that if you choose to “conditionalize” a *.cljs file by first renaming it to *.cljc, it stays in the same directory.

whitecoop21:01:22

Is there a way to get a list of all the ^:exported symbols during compilation? I looked over the cljs compiler options, but didn't see anything that seemed to do that

dnolen21:01:13

there’s no out of the box way but you can probably do that with cljs.analyzer.api

whitecoop21:01:55

@dnolen ok. I'd like to be able to take the nested calls (e.g. my-ns.core.some-fn) and wrap them in top level js functions (e.g. function some_fn() {return my_ns.core.some_fn();}) and if I had that list I could do this more easily.

dnolen21:01:52

@whitecoop ok though I don’t understand why you need to do that?

joshkh21:01:17

@josh_tackett there are a few examples in cljs-ajax's README file: https://github.com/JulianBirch/cljs-ajax#getpost-examples it looks like the pattern is to provide functions to :handler and :error-handler. in terms of displaying the results somewhere, i'd recommend a framework (or not a framework depending who you ask!) like re-frame. there's an existing "effect" you can use to make that happen: https://github.com/Day8/re-frame-http-fx

thheller21:01:02

@whitecoop you can manually call (defn my-fn [] ...) (js/goog.exportSymbol "theName" my-fn) if you want the name exported

thheller21:01:27

no need to do that via ^:export

whitecoop21:01:36

@dnolen I'm using the compiled js in Google Apps Script and Apps Script requires that custom functions (for use in Google Sheets) be declared as top-level functions.

dnolen21:01:17

@whitecoop @thheller’s point is also true, if you want to export your own name that’s the way to go

dnolen21:01:42

^:export is just sugar for the typical case

whitecoop21:01:33

@thheller @dnolen ah. So "theName" would then be available at theName() -- no nested call required? (Not real familiar with the Closure compiler)

whitecoop21:01:41

:thumbsup: That's what I need. Thanks @dnolen @thheller