This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-01-17
Channels
- # adventofcode (2)
- # beginners (153)
- # cider (14)
- # clara (9)
- # cljs-dev (8)
- # cljsjs (1)
- # cljsrn (4)
- # clojure (124)
- # clojure-dev (9)
- # clojure-france (18)
- # clojure-greece (22)
- # clojure-italy (11)
- # clojure-nlp (5)
- # clojure-russia (9)
- # clojure-spec (21)
- # clojure-uk (40)
- # clojurescript (82)
- # core-async (12)
- # cursive (3)
- # data-science (2)
- # datomic (225)
- # devcards (8)
- # docs (2)
- # duct (1)
- # emacs (18)
- # figwheel (2)
- # fulcro (117)
- # graphql (13)
- # hoplon (10)
- # jobs (7)
- # jobs-discuss (7)
- # keechma (8)
- # leiningen (4)
- # off-topic (16)
- # om (2)
- # om-next (3)
- # perun (11)
- # precept (4)
- # re-frame (24)
- # reagent (2)
- # remote-jobs (8)
- # ring (2)
- # ring-swagger (9)
- # rum (42)
- # shadow-cljs (8)
- # spacemacs (3)
- # specter (7)
- # uncomplicate (10)
- # unrepl (58)
- # yada (9)
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).
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?
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
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
@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?
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
}
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.")
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?@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 ?
does anybody else have trouble finding a list of recent releases of cljs on github via their tags list?
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
@gfredericks The front page of http://clojurescript.org links to the changes.md file
@karl.jakob.lind I put an example in a gist: https://gist.github.com/alexanderkiel/cfc57785b2c87ac71af6bffb792f8251
@gfredericks It is as if GitHub truncates the tags list to around 100 tags
100 ought to be enough for anybody
GitHub’s behavior is consistent with this program: (take 4 (reverse (sort ["r3308" "v1.8" "v1.9" "r3297" "r1.9.946"])))
It is a bit unfortunate that all of ClojureScript’s recent tags sort as being older than the existing rNNNN
tags.
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?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 " ")))
following this tutorial: http://clojurescriptmadeeasy.com/blog/how-to-make-remote-calls.html
are you calling that test function? because remember that make-remote-call now returns a channel
although I take that back because it’s weird you are actually getting a response with status = 0
ya I see the request making it to the backend, but the response is the issue
the backend completes successfully, but there is nothing on the frontend
(defroutes app-routes
(GET "/" []
{:status 200
:body "TEST"})
(route/not-found "Not Found"))
(def app
(wrap-defaults app-routes site-defaults))
That's the routes on the backend @lee.justin.m ^^^
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
I really can’t understand how you are getting a response that looks like a cljs-http response but has status = 0
logging is showing in both
prn in test -> #object[cljs.core.async.impl.channels.ManyToManyChannel]
prn in make-remote-call -> {:status 0, :success false, :body "", :headers {}, :trace-redirects ["
okay that seems as expected. try pointing the code to a public website mabye? see if it is on the backend or the frontend
{:status 0, :success false, :body "", :headers {}, :trace-redirects ["
tried google
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
Should we put this back in the big channel?
@lee.justin.m Let me know what you find out. I'm a bit stuck right now
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?
nope, no auth
@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.
sorry try one more thing: hit this url http://api.icndb.com/jokes/22
^^ @josh_tackett that url will actually return a status 200 without redirecting to https
you should get Response: {:status 200, :success true, :body {:type NoSuchQuoteException, :value No quote with id=22.}, :headers {content-type application/json}, :trace-redirects [
@josh_tackett did any of that help?
@lee.justin.m Sorry had to go to a meeting, same issue: {:status 0, :success false, :body "", :headers {}, :trace-redirects ["
@lee.justin.m also the curl to local gives a 200
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.
@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.
@lee.justin.m Thank you Maybe someone else can solve this one? See thread ^^^
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.
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.
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 😞
@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
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
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
@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?
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
@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.
Is there a way to get a list of all the ^:export
ed symbols during compilation? I looked over the cljs compiler options, but didn't see anything that seemed to do that
@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.
@whitecoop ok though I don’t understand why you need to do that?
@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
@whitecoop you can manually call (defn my-fn [] ...) (js/goog.exportSymbol "theName" my-fn)
if you want the name exported
@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.
@whitecoop @thheller’s point is also true, if you want to export your own name that’s the way to go