This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-01-14
Channels
- # beginners (4)
- # boot (78)
- # braveandtrue (3)
- # cider (9)
- # clara (6)
- # cljs-dev (4)
- # clojure (57)
- # clojure-brasil (1)
- # clojure-russia (99)
- # clojure-spec (20)
- # clojure-uk (40)
- # clojurescript (162)
- # component (17)
- # cursive (4)
- # datomic (21)
- # docker (2)
- # emacs (5)
- # figwheel (2)
- # hoplon (363)
- # jobs (1)
- # leiningen (1)
- # om (4)
- # om-next (5)
- # onyx (10)
- # proton (1)
- # re-frame (13)
- # reagent (13)
- # ring (3)
- # rum (1)
- # slack-help (1)
- # test-check (3)
- # untangled (7)
- # vim (24)
hello guys! what editor do you recommend to use nowadays?
@leo.ribeiro Lately I use LightTable and a few terminal windows to do most of my developing. Atom has ProtoREPL that is cool. The next step up, imo, is Emacs and that can be its own adventure in itself. There are some projects on github that have very nice initial settings like Prelude or the one by Bodil..
@sova thannks for the feedback… I’m giving a shot on Emacs… enjoying but what a challenge haha
@leo.ribeiro my most productive coding days are from my emacs days. M+x cider-jack-in 4life
Right now I've been tinkering, since it's less codingcoding and more design. Flexibility in tooling. Emacs undo tree is excellent, though! Much missed feature from the rest.
@leo.ribeiro @sova The Clojure Survey asks this question so we have data. The following link is one year out of date, but it is indicative (search for "DEVELOPMENT ENVIRONMENT" on this page): http://blog.cognitect.com/blog/2016/1/28/state-of-clojure-2015-survey-results My guess is that Cursive will be higher when this year's figures are published. It is commercial, but some regard it as having an easier learning curve than emacs. Shrug. Depends what you already know.
@stuartsierra I ran into a very similar issue the other day and it turned out to be an order of evaluation issue: https://github.com/cljsjs/packages/issues/697#issuecomment-271292601
did someone encounter "Malformed transit" exception when making requests from cljs-ajax to ring-transit middleware?
ok I can't seem to find a working combination of ring middleware and cljs client to send clojure datastructures request from browser to server 😞
tried https://github.com/ngrunwald/ring-middleware-format and https://github.com/jalehman/ring-transit
@leov when you inspect the transit that’s being sent, can you decode it on the repl?
I use
(-> (:body @tmp) #_(java.io.ByteArrayInputStream. (.getBytes @tmp))
(cognitect.transit/reader :json)
(cognitect.transit/read))
second is simpler so should be easier to debug, but I don't know what to do next. I can decode the body myself through the snippet above, and it more or less matches to the decoding in middlewares code
I don't know what debugging technique to apply. Currently I do (reset! tmp ring-request)
in my ring handler, but :params
is empty there, and :body
is unchanged
ok, this means that cljs-ajax/PUT is somewhat incorrect in this form `(PUT "/transact" {:params (select-keys @my.w/server [:net-config]) :handler (fn [r] (swap! my.w/server merge r))})`
have you tried POST instead of PUT?
try to find a minimal reproduction of the problem
ideally, capture the request in the chrome devtools and use "copy as cURL"
then repeat from the command line, with the simplest possible data structure
we use ring-transit + cljs-ajax successfully, and so do many others
I am able to manually decode it via the snippet above, but ring-transit middleware somehow I guess reads it twice or something, judging by the exception java.io.EOFException
it's still
[#error {
:cause nil
:via
[{:type java.lang.RuntimeException
:message "java.io.EOFException"
:at [com.cognitect.transit.impl.ReaderFactory$ReaderImpl read "ReaderFactory.java" 114]}
{:type java.io.EOFException
:message nil
:at [com.cognitect.transit.impl.JsonParser parse "JsonParser.java" 44]}]
:trace
[[com.cognitect.transit.impl.JsonParser parse "JsonParser.java" 44]
[com.cognitect.transit.impl.ReaderFactory$ReaderImpl read "ReaderFactory.java" 112]
[cognitect.transit$read invokeStatic "transit.clj" 297]
[cognitect.transit$read invoke "transit.clj" 293]
[ring.middleware.transit$read_transit invokeStatic "transit.clj" 35]
[ring.middleware.transit$read_transit invoke "transit.clj" 27]
[ring.middleware.transit$transit_handler$fn__6723 invoke "transit.clj" 57]
what other middleware do you use?
try removing it all except for ring-transit
also remember that order matters
the request body in ring is a InputStream which can only be read once
if you "slurp" it once, it's gone
the exception points to that. I am puzzled because when I disable this exact middleware, I am able to slurp the body, however when I enable this last middleware, it throws the exception as if it somehow have the body already slurped
can you post your midleware pipeline?
meep.
(defn wrap-everything [handler {enable-csrf? :enable-csrf?}]
(-> handler
;; (wrap-restful-format :handlers [])
;; (ring.middleware.format-params/wrap-transit-json-params)
;; (ring.middleware.format-response/wrap-transit-json-response)
wrap-transit-response
(wrap-transit-body {:keywords? false ; ;
:malformed-response-fn (fn [e r h] (reset! tmp [e r h]) {})
})
(wrap-defaults (-> (if (= (env :clj-env) "production")
(-> secure-site-defaults
(dissoc-in [:security :hsts])) ; TODO: remove; always returns empty 200 for some reason
site-defaults)
(assoc :proxy true)
(my.tools/deep-merge {:session {:store
(cookie-store {:key (or (env :secret-key)
"dev-key 16 bytes")})}})
(#(if enable-csrf? % (dissoc-in % [:security :anti-forgery])))))
wrap-cljsjs
wrap-with-logger
wrap-gzip))
(def http-handler
(compojure.core/routes (wrap-everything (-> (compojure.core/routes my.saml/routes))
{:enable-csrf? false})
(wrap-everything (-> routes
(my.saml/wrap-allowed-users allowed-user?)
my.saml/wrap-saml-authentication)
{:enable-csrf? false})))
are you calling routes twice?
(defroutes routes
(GET "/" _
{:status 200
:headers {"Content-Type" "text/html; charset=utf-8"}
:body (io/input-stream (io/resource "public/index.html"))})
(GET "/world" {session :session}
{:status 200
:body (merge @world
{:current-user (:saml session)})})
(POST "/transact" {:keys [session params] :as req}
{:status 200
:body (do
(reset! tmp req)
(merge @world
{:current-user (:saml session)}))})
(resources "/"))
I'd get rid of everything and start with a minimal pipeline
especially remove wrap-defaults
also you should have a reloading setup so you don't have to restart the repl to make changes to the middleware 🙂
that makes all the difference, believe me
try restarting the repl?
also get rid of the routes entirely 🙂
it may be that ring-transit is run twice
(you may actually see that in the full stacktrace)
right there where I compose two different handlers, and wrapping them with my 'defaults' vinaigrette
also I've no idea how to write compojure routes in a safer manner. it's the second or a third time I shoot myself in a foot. Move middlewares up or a down the stack a little, or try disabling CSRF for some routes - and the best would be something like this, and other times it will be a plain security problem
Hey peeps! I'm working on an ECS library for clj/cljs with the target being for game dev in cljs coupled with either a pixi.js or phazer.js wrapper. I've got something set up atm but I'm not too happy about the performance (I know running on JS doesn't help) and I was wondering if anyone would have any tips on what data structures to use and maybe operations on those data structures. I 'm trying to keep if fully functional with immutable data structures, not sure if it will be possible because of the performance penalization, but I'm not too informed on how to optimize the clojure datastructures
@leov, I find using bidi a bit easier
well ok yesterday I spent an hour debugging a bidi problem (my fault of course) but in general it's a bit less magical
@pesterhazy, for this example - 1) I must test some routes in compojure without CSRF protection, then move on to main app logic. 2. I want CSRF protection to be before any other middleware 3. I want ring-transit middleware am I correct it's just impossible to satisfy all 3 with compojure and ring?
not sure
if I am correct, compojure goes something like this (some-> handler1 handler2 ..)
well during the compilation I guess, with macros (might be very wrong about this)
no problem at all
and when ever I attempt to load new namespace in to repl :required namespaces can’t be found
what can i do about this
(cljs.reader/read-string (pr-str (js-obj 0 "a")))
triggering TypeError: Cannot read property '0' of null
@thedavidmeister (pr-str (js-obj 0 "a”))
=> #js {:0 "a”}
, that keywordized number chokes reader
(cljs.reader/read-string (pr-str (js-obj “k" "a")))
works
@darwin yeah, in the real app i'm getting the object from a 3rd party 😞
i managed to work around with a js->clj
call in between 🙂
Keywords are useful code constructs, but if they don't fit the data you're dealing with, don't use them.
@potetm this is what i'm hearing
something i'll have to chase up another day
i'm sort of just being forced to refactor due to breaking changes in vendor code
trying to keep it as "light touch" as possible 🙂
all the casing rules for the names of things just had to change of course, and things that were arrays are now objects with numeric indexes too apparently >.<
cheers for the advice though
Noob here: How can I use Om[Next] to generate AMP tags (i.e. amp-img)?
Does anyone have experience using semantic-ui-react with clojurescript/reagent? I'm trying to figure out how to set up the deps.clj with the minified umd file generated by semantic-ui-react using :module-type :commonjs
but I'm having trouble importing basic components like a Buttons. Wondering if anyone else has experimented with this library.
I suppose a better question is does anyone know of any examples of using a commonjs lib bundled to umd from clojurescript?
@triss, ...any chance you might be using (ns your-ns)
to switch interactively? In cljs, you'll want to use (in-ns 'your-ns)
@triss, ...otherwise the bare definition will overwrite the aliases &c. from a prior ns declaration, making them unavailable.
hm, when i run lein cljsbuild once
i get Caused by: clojure.lang.ExceptionInfo: No such namespace: , could not locate .cljs, .cljc, or Closure namespace " "
how would i pin point what the "emtpy" namespace comes from
@kokos tricky, I would start bisecting parts of your project or reverting recent changes
@kokos if you are desperate 😀 you could try to use tools.namespace
, fetch all the ns declarations of your cljs files and either use a simple regex or conform with specs
I'm having some issues understanding lein, repls and what I should expect to work in clojurescript. Is this the right place to ask questions or is there a different channel I should head to?
@naddeoa, there might be a more specific place for some of the individual questions, but there's no reason you can't start here.
cool. I'm trying to get set up with spacemacs. I'm normally a Vim user but I had this recommended to me. I made a project with lein new mies
which has a bunch of scripts for repls/buliding etc. Those work fine. In order to use the emacs buffer though it looks like I need to use something called nRepl?
I can use lein repl
, but it looks a lot like a clojure repl and complains about not finding .clj files and .class files, which smells like Java
@naddeoa, ...so, nrepl is a protocol; the modern emacs client for that protocol is called CIDER
interesting. I know that the project's repl script is just this:
(require
'[cljs.repl :as repl]
'[cljs.repl.node :as node])
(repl/repl (node/repl-env))
Running that gives me a functional repl, but how that is supposed to hook up to nRepl is a mystery to me
which... frankly, I don't personally have figwheel working with CIDER right now, so I'm not a good person to give advice on it (though it certainly can be done).
so, whenever I read something I shouldn't assume that it will just work on clojurescript then
weird, but I know that the file above does run a repl, and I don't think figwheel is involved
Piggieback is if you want a cljs repl and figwheel handles live reloading of code in the browser
spacemacs has been really nice so far. It prompted me to install the layer when I opened a cljs file
I'm not at my computer atm so I can't double check, but I believe it's by bbatzov, who maintains cider
so, do you know what piggieback would be doing that my repl script (part of the meis template) isn't?
Alt-x (might be SPC SPC or SPC :) should allow you to start typing in the letters for the command and suggest possible options
Its just odd to have 4 different ways to start a repl and not have any of them talk about each other online
With cider you don't need to specify the dependencies for starting the repls anymore which is really nice