This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-03-27
Channels
- # aleph (5)
- # announcements (18)
- # beginners (200)
- # cider (25)
- # cljdoc (4)
- # cljsrn (3)
- # clojure (90)
- # clojure-europe (3)
- # clojure-finland (5)
- # clojure-france (1)
- # clojure-houston (1)
- # clojure-italy (8)
- # clojure-nl (15)
- # clojure-spec (24)
- # clojure-uk (20)
- # clojurescript (199)
- # core-async (2)
- # cursive (45)
- # data-science (14)
- # datomic (33)
- # duct (13)
- # fulcro (4)
- # graphql (3)
- # kaocha (9)
- # leiningen (24)
- # nrepl (16)
- # off-topic (105)
- # pathom (15)
- # pedestal (28)
- # re-frame (1)
- # reagent (14)
- # shadow-cljs (28)
- # spacemacs (8)
- # tools-deps (8)
- # vim (4)
Hi! I have an issue where my cljs build now produce a goog not defined
error, it started after I did a lein clean
the answers I found on google apply to shadow.cljs but I don't use it, and not sure how to fix it
@archibald.pontier_clo do you use a build config without a :main
or :modules
entry?
@thheller sorry for the late reply, no 404, and yes I am loading the correct file, enabling whitespace optimization in project.clj
stopped the error without any other change in the code
Is there any reason not to use syntax-quote at runtime? The docs say “Only intended for use in Clojure macros” (http://cljs.github.io/api/syntax/syntax-quote) but I’m not sure why. eg: https://www.maria.cloud/gist/c2282b77e2e47d71cb68b3becce8f84c?eval=true
I suspect it may have issues with properly namespace qualifying symbols in certain nested scenarios, as namespaces or vars don't exist at runtime in (non self-hosted) cljs
those are some very good docs btw, good job @shaunlebron
that is true. that is also a problem when using syntax-quote in macros, as the clj namespace doesn’t know about vars in cljs namespaces.
@mhuebert it’s mainly a guidepost for me to say “syntax-quotes are built for macros and nobody uses them otherwise and perhaps they shouldn’t be”
@shaunlebron that's not true tho
sweet, how?
the entire tools.emitter symbolic bytecode is expressed through syntax-quoted templates
https://github.com/clojure/tools.emitter.jvm/blob/master/src/main/clojure/clojure/tools/emitter/jvm/emit.clj#L214-L230 as an example
so you’re creating a defmethod where the body’s code is generated at compile time, or rather evaluate time?
this is making my brain fold
I might ping @mfikes to see how much of this is possible in cljs before amending the docs
typing
`[~@(when x whatever) 1 2 ]
is literally a shortrand for typing (vec (concat (when x whatever) (list 1) (list 2)))
wow, just like matt’s example in maria, i did not know this
user=> '`[~@(when x whatever) 1 2 ]
(clojure.core/apply clojure.core/vector (clojure.core/seq (clojure.core/concat (when x whatever) (clojure.core/list 1) (clojure.core/list 2))))
i need to stare at this for a minute
too many questions
in different directions
how do i trace what’s going on
i inserted references to the reader code in the docs, maybe i have to look at them more closely
think about this in clojure not clojurescript, trust me that in this case there's no difference and it'll make it a bit easier to grasp
user=> (read-string "`[~@(when x whatever) 1 2 ]")
(clojure.core/apply clojure.core/vector (clojure.core/seq (clojure.core/concat (when x whatever) (clojure.core/list 1) (clojure.core/list 2))))
user=> (read-string "'`[~@(when x whatever) 1 2 ]")
(quote (clojure.core/apply clojure.core/vector (clojure.core/seq (clojure.core/concat (when x whatever) (clojure.core/list 1) (clojure.core/list 2)))))
this is helping: https://github.com/clojure/tools.reader/blob/tools.reader-1.3.0/src/main/clojure/clojure/tools/reader.clj#L693
that helps too, yeah
yes, the thing to grasp I guess is that syntax-quote delegates the templating at runtime
otherwise you could only syntax-quote forms containing constant values, which wouldn't be very interesting
when somebody says "x only works in macros", they forget that a macro is just (big handwaves here) (eval (the-macro-as-a-function args))
yeah that helps, my understanding is better
hard to keep the evaluation differences between clj and cljs in my head and to see how that affects this
so it does, since that can certainly affect it
well, and that's a big if. if name resolution doesn't work as expected, then at the least I would want to understand exactly how
like resolving vars at runtime i think
that is different than doing simply
`+
`, where read-time is being executed at compile timeit can get really confusing when you can nest stages like this (`read-string` is nothing but read-time available a-la-carte at runtime!), but this is what makes lisps so powerful :)
i think i need to hold on to the issue of name resolution, i don’t understand how read-string
affects that
we’re talking about cljs now
either cljs-js or cljs-jvm
yeah, read-string is the runtime read-time thing
self hosted cljs does have reified namespaces and var I think so that makes it similar to clojure (but I never used it so I'm not sure)
but is read-string
being invoked when syntax quotes are read you mean?
you can think of (non-self hosted) clojurescript as:
(cljs.emit/emit (cljs.analyzer/analyze (clojure.tools.reader/read-string <..>)))
yeah?
tools.reader on the jvm reads that, interops with the namespace map of the clojurescript analyzer which is available at compile time, and returns cljs.core/+
to the analyzer
wow yeah, this makes sense so far
ok, now all the examples that I shown you before can be explained and understood by replacing <..>
with them :)
> but even that is not a problem unless you’re using syntax-quote inside a read-string
ok, i’ll try to come up with an example to put in the docs for this
thanks for that tour, crazy and helpful!
(fn [cb]
(let [id (atom -1)
frame (fn [] (reset! id (requestAnimationFrfame
(fn []
(cb %)
(frame)))))]
(frame))
Hey I'm trying to write a unit test with this clause: (is (thrown? js/Object (ig/unique #{:just-me :no-theres-me-too!})))
But it's failing:
Testing for a thrown error?
yes. Should I be specifying some type other than js/Object?
What does the unit test say?
Fail with what?
(js/Error. "Non-unique")
So at least JS is throwing the error
Its just that the test isn't wrapping around it, catching it
That's right. The test is failing when it should fail if there isn't an error
Its clj sibling works fine: (is (thrown? Exception (ig/unique #{:just-me :no-theres-me-too!})))
Ya... my first thought
The js object namespace is wrong
Because the docs say it will check if error is thrown on exact class you give it
js/Object most likely is not the parent namespace of Exception being thrown
You'd think it would be... like Ruby. Everything is an Object. But JS breaks all the rules. I never assume in JS
Can you change js/Object to Exception... just like the working test
The JS throws error as.expected. but the test isn't seeing it thrown on the js/Object namespace
So I'm trying this:
(.log js/console "blih") (try (/ 1 0) (catch js/Object e (.log js/console (str (type e))))) (.log js/console "bleh")
And what's showing up is this:
Firefox 66.0.0 (Ubuntu 0.0.0) LOG: 'blih' Firefox 66.0.0 (Ubuntu 0.0.0) LOG: 'bleh'
I was hoping I could get it to tell me what type the error was.
So you can catch the specific error?
More granular than Exception
Inspect e
The exact exception is probably burried in the e variable
Instead of type e, just console log the e
str is just returning the top text from e object... browser, ubunutu... looks like a header string
Need to go inside e, more levels
FAIL in (utility-test) (cljs/test.js:373:11) (thrown? js/Object (ig/unique #{:no-theres-me-too! :just-me})) failed with
I think you need a ( in front of function call
Otherwise, it is a parameter to a function
(is (thrown? js/Object (ig/unique #{:just-me :no-theres-me-too!})))
It is testing for an error to be thrown?
@jayzawrotny as far as I am aware let in cljs is a let*. This means that the name frame is not bound to a value until the expression (which references frame) is evaluated.
Yes, it’s trying to eval all the forms but the frame symbol is not bound at that point yet.
@jayzawrotny you have the reasoning for why it isn't working correct.
@jayzawrotny you can also do (let [f (fn fact [n] (if (= n 0) 1 (* n (fact (- n 1)))))] BODY)
@jayzawrotny it is probably a better way to do it.
@eric.d.scott what's ig
in this case?
The namespace where the function 'unique' lives. Expects a singleton, and throws an error otherwise
Print out the entire e in the console
I am sure the exact namespace is inside var e
str is just giving you a browser agent header
Yes I actually started with js/Error, then saw cases where people claimed js/Object was the way to go.
Javascript doesn't use a class inheritance system... its a prototypal
Not everything inherits from Object in JS
Like Ruby does... where everything is an Object
I will verify that, right now, for you
here is an example, to find out who is the parent of an object, e being the object in this case…
set hidden field message_receiver_id = 2 var t = “” undefined t.isPrototypeOf ƒ isPrototypeOf() { [native code] } t.isPrototypeOf ƒ isPrototypeOf() { [native code] } t.instaneof undefined t.instanceof undefined typeof t “string”
We don’t recommend catching errors on Exception in Ruby because it will catch all errors, when the test is targeting very specific errors
@eric.d.scott I don't understand why js/Object
is preferred here, and would probably disagree w/
@dnolen loved the talk on clojure.spec
hi guys, sorry if stupid question but i worked sometime now on clojure but i can’t say i am exactly a guru 🙂.
So i have this regular expression in a cljc file
#"(?i)<\/?((script|style|input){1})(\s?[^<>]*)>"
in the js file it becomes:
/<\\/?((script|style|input){1})(\s?[^<>]*)>/i
that… 🎉
gives me this error:
var x = /<\\/?((script|style|input){1})(\s?[^<>]*)>/i
VM1576:1 Uncaught SyntaxError: Unexpected token {
in clj it works very well, this file has been a clj file for some time now and it always worked, i turned it into a cljc and i got this problem in js
if you wonder:
[org.clojure/clojure "1.10.0-alpha7"]
[org.clojure/clojurescript "1.10.238"]
https://stackoverflow.com/questions/36775526/regex-patterns-in-java-vs-javascript seems relevant
Issue: cookies don’t save http://dev.localhost:8080/authentication - ring server http://dev.localhost:9500/log-in - re-frame SAP I send JSON from SAP to server by https://github.com/Day8/re-frame-http-fx, cookies don’t save in web browser If i run directly http://dev.localhost:8080/authentication cookies save in web browser I added
(-> (handler request)
(header "Access-Control-Allow-Origin" "")
(header "Access-Control-Allow-Credentials" "true")
(header "Access-Control-Allow-Headers" "Content-Type, User-Agent"))
and
(wrap-session {:store (jdbc-store postgres/db {:table :sessions})
:cookie-name "auth-session"
:cookie-attrs {
:http-only false
:same-site :lax
:secure false ; https
;:domain "dev.localhost"
;:max-age 1800
}})
Am I miss something? Am I doing something wrong about cookies security or there is an issue about how I use https://github.com/Day8/re-frame-http-fx and cookies? Any hints how to debug it / solve it? I stuck with it. I have to miss something.When I add [:img {:src "
cookies save so it is about https://github.com/Day8/re-frame-http-fx and goog.net.XhrIo
(`XMLHttpRequests`) queries
*I don’t recommend to set all this options in server for security reason. I set them to find the issue.
@nathantech2005, @dnolen Thanks for your help. I finally wound up going with the following:
(defn erroneous-unique [] "Couldn't get (thrown?...) to work" (try (ig/unique #{:just-me :no-theres-me-too!}) (catch :default e :error))) (deftest ... (is (= erroneous-unique) :error) ...
@eric.d.scott I am not in topic, but why not (is (thrown? …))
?
am I allowed to ask a question about raw Javascript? We can thread it. I am looking for a send method in JS… to dynamically make a method call on an object.
exactly what I was looking for
@kwladyka - the problem was getting the throw? clause to key on the error class. Nothing I tried made it happy, and the test kept failing.