This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-10-27
Channels
- # aws (3)
- # aws-lambda (8)
- # bangalore-clj (1)
- # beginners (155)
- # boot (13)
- # cider (88)
- # cljs-dev (3)
- # cljsrn (9)
- # clojure (120)
- # clojure-india (1)
- # clojure-italy (2)
- # clojure-norway (1)
- # clojure-romania (2)
- # clojure-russia (41)
- # clojure-spec (4)
- # clojure-uk (34)
- # clojurescript (68)
- # core-logic (16)
- # cursive (11)
- # data-science (9)
- # datomic (19)
- # dirac (6)
- # duct (20)
- # emacs (7)
- # events (2)
- # figwheel (4)
- # fulcro (12)
- # graphql (1)
- # hoplon (68)
- # klipse (1)
- # leiningen (7)
- # lumo (11)
- # off-topic (9)
- # onyx (114)
- # pedestal (4)
- # protorepl (15)
- # re-frame (60)
- # reagent (3)
- # ring (18)
- # shadow-cljs (15)
- # spacemacs (82)
Heed help on this error http://clojureverse.org/t/invalid-arity-0-with-using-a-macro/612
@jiyinyiyong 1. Generate a let
in your macro or you'll duplicate all your passed props
code many times and possibly suffer from multiple execution of code that you wouldn't expect
@jiyinyiyong Well first post the result of the macroexpand. Also, name your anonymous functions that you see in the stacktrace
foo.core$macros=> (defmacro $ [tag props & children]
#_=> `(let [props# ~props
#_=> attrs# (respo.util.list/pick-attrs props#)
#_=> styles# (if (contains? props# :style) (sort-by first (:style props#)) (list))
#_=> event# (or (:on props#) (:event props#) {})
#_=> child-map# (respo.util.list/arrange-children-old ~children)]
#_=> {:name ~tag,
#_=> :coord nil,
#_=> :attrs attrs#,
#_=> :style styles#,
#_=> :event event#,
#_=> :children child-map#}))
#'foo.core$macros/$
foo.core$macros=> (macroexpand '(foo.core/$ :div {} []))
(let*
[props__41__auto__
{}
attrs__42__auto__
(respo.util.list/pick-attrs props__41__auto__)
styles__43__auto__
(if
(cljs.core/contains? props__41__auto__ :style)
(cljs.core/sort-by cljs.core/first (:style props__41__auto__))
(cljs.core/list))
event__44__auto__
(cljs.core/or (:on props__41__auto__) (:event props__41__auto__) {})
child-map__45__auto__
(respo.util.list/arrange-children-old ([]))]
{:name :div,
:coord nil,
:attrs attrs__42__auto__,
:style styles__43__auto__,
:event event__44__auto__,
:children child-map__45__auto__})
foo.core$macros=>
Hi! I have 2 tooling needs:
- Anyone using a robust/trustworthy code coverage reporter for clojurescript?
- Say I want to move (def x ...)
from ns A to ns B, how do you do it automatically (due to x
being used in many consumers ns's)? https://github.com/clojure-emacs/clj-refactor.el/wiki/cljr-move-form seems broken for cljs. Does Cursive or others work well for this?
@jiyinyiyong that doesn’t look correct (respo.util.list/arrange-children-old ([]))
, thats the arity 0 error since you are calling a vector with zero args
@thheller thanks, fixed child-map# (respo.util.list/arrange-children-old (list ~@children))]
Can someone here share experience on connecting to a figwheel repl with the intellij plugin Clojure-Kit?
Hi all: trying some more examples with code splitting, specifically the example António Monteiro shows in his clojuere/conj talk:
https://youtu.be/63K--ctvT-g?t=937
TLDR, it involves splitting common vendor libraries, like reagent, into their own module. Here is a very simple gist that implments the example:
https://gist.github.com/zalky/47dd7ee21f713b532fcb45093956d7c1
While the example works in the browser, I end up with no js in app.js
, no js in vendor.js
, and a bit of js in data.js
implementing the vars in data.cljs
. Presumably much of the missing js ended up in cljs_base.js
. I would have expected some js in app.js
implementing the vars in app.cljs
, and based on the talk and the Clojurescript documentation, I would have also expected reagent.core
, and it's dependencies, like cljsjs.react
, to be in vendor.js
, which is empty. (Using cljs 1.9.946).
Clearly I'm missing something. Thoughts?
Yeah but don't I have to use js/goog.global.location.hash
then? With the result of having to be careful about the name goog
?
or is plain goog.global.location.hash
or goog/global.location.hash
acceptable?
I know both of those forms work in practice, but not sure if they're frowned upon
@pesterhazy Curious if (.-hash js/location)
works.
It works, and so does js/location.hash
Does anyone know how to get http headers out of a request with cljs-ajax? Or do I have to find another library?
first you need to whitelist the headers server-side, for example:
(defn wrap-expose-headers
[handler]
(fn [request]
(let [response (handler request)]
(assoc-in response [:headers "Access-Control-Expose-Headers"] "Access-Control-Allow-Headers,Access-Control-Allow-Methods,Access-Control-Allow-Origin,Content-Length,Date,Server"))))
Then in a handler:
(defn response-handler [[ok xhrio]]
(if ok (let [response (.getResponse xhrio)
headers (.getAllResponseHeaders xhrio)]
(re-frame/dispatch [:response-convert {:response response :headers headers}]))
(let [error-response (.getResponse (:response xhrio))
headers (.getAllResponseHeaders (:response xhrio))]
(prn headers))))
(ajax.core/ajax-request
{:uri "/enpoint"
:method (:method request)
:headers (:headers request)
:params (:body request)
:format (text-request-format)
:response-format {:read identity :description "raw"}
:handler response-handler})
@mfikes the context was a let binding like this: https://gist.github.com/pesterhazy/2bd06fc6e12686e0705763988099b3c5
in such a context, the let binding will shadow js/location
, but not goog/global.location.hash
yeah I never particularly liked that syntax (I've always felt like it worked by accident)
to me it's similar to js*
- kind of rough around the edges
IMHO, it feels like if you are using dots in your symbols, you might be essentially embedding JavaScript in your ClojureScript.
Sane:
cljs.user=> (defn foo []
(let [location 12345] (prn (.-hash js/location))))
WARNING: js/location is shadowed by a local at line 2 <cljs repl>
the compiler warning is definitely super helpful
doesn't always work though:
cljs.user=> (do (set! js/global.location #js{:hash "correct"}) (let [location #js{:hash "incorrect"}] (prn js/location.hash)))
"incorrect"
(tested in lumo)
same in planck 2.8.1
if you instead write that as
(do (set! (.-location js/global) #js{:hash "correct"}) (let [location #js{:hash "incorrect"}] (prn (.-hash js/location))))
you get the same JavaScript, along with a nice warning about shadowingI have a CLJS source file containing a map, part of which I would like to translate into a DOT file for drawing with GraphViz. I wrote a function to translate the map that I can call from the Figwheel repl only I just realised I don't have spit
or anything to actually write the DOT syntax onto disk. Or do I? Did I miss a way to write files?
if the cljs ends up running as js in a browser, then there’s not an exact equivalent to spit
unless you use something like node webkit to run things
or you have the cljs end up running in a node environment
if you are running the cljs as js in the browser, you can try the html5 file apis
it looks like you can have figwheel work with node, https://github.com/bhauman/lein-figwheel/wiki/Node.js-development-with-figwheel
thanks for the suggestions, i was just hoping i'd missed some supported alternative to spit. I'm not doing this so often than C&P is a terrible solution
one option is to generate a download prompt for the file
I suppose your data is runtime data, so it might not be possible (to get a macro to spit
the data out)
data uris are pretty easy to use https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs
Using hiccup, is there a way to set a bare data attribute? [:div {:data-my-attr true}]
will return <div data-my-attr=true></div>
when the desire is to get <div data-my-attr></div>
first you need to whitelist the headers server-side, for example:
(defn wrap-expose-headers
[handler]
(fn [request]
(let [response (handler request)]
(assoc-in response [:headers "Access-Control-Expose-Headers"] "Access-Control-Allow-Headers,Access-Control-Allow-Methods,Access-Control-Allow-Origin,Content-Length,Date,Server"))))