This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-10-31
Channels
- # bangalore-clj (3)
- # beginners (15)
- # boot (128)
- # cider (4)
- # cljs-dev (12)
- # cljsjs (1)
- # clojure (105)
- # clojure-austin (5)
- # clojure-canada (6)
- # clojure-italy (5)
- # clojure-russia (14)
- # clojure-spec (70)
- # clojure-uk (21)
- # clojurebridge (3)
- # clojurescript (264)
- # cloverage (6)
- # cursive (4)
- # data-science (6)
- # datomic (10)
- # dirac (5)
- # editors (30)
- # events (3)
- # hoplon (9)
- # klipse (7)
- # leiningen (3)
- # luminus (4)
- # off-topic (9)
- # om (5)
- # om-next (1)
- # onyx (1)
- # parinfer (2)
- # perun (28)
- # re-frame (5)
- # ring (1)
- # rum (11)
- # spacemacs (2)
- # specter (10)
- # sql (3)
- # uncomplicate (4)
- # untangled (67)
- # vim (2)
- # yada (1)
not sure if i should post this in here or in the clojure chat
i wrote a script that looks for namespaces using clojure.tools.namespace.find
it works fine with .cljc
files until i try to use #?(
syntax in the ns
at the top
then the namespace mysteriously disappears from what clojure.tools.namespace.find/find-namespaces-in-dir
can see
anyone seen any behaviour like this at all?
@thedavidmeister Is it possible to post the ns form under discussion? Heard similar issues in the ns form.
@iku000888 yup, i’ll put something up in a sec
I'm refactoring an app I wrote about a year ago (my first web app !) to use the reagent atom instead of cljs.core/atom, and hopefully clean up a lot of the state management logic.
(It's this app here: http://gregor-samsa.herokuapp.com/register-machine.html)
I guess I'm a little unclear on how to accomplish my goal: ideally I'd like the input atom to result in a stack of inputs. Is the "correct" way to do this in reagent to keep the stack in a separate component?
i tried this
(ns styles.card
(:require [garden.units :as u]
[styles.colours]
[styles.spacing]))
#?(:cljs (require '[garden.def :refer-macros [defstyles defrule]]))
#?(:clj (require '[garden.def :refer [defstyles defrule]]))
@iku000888cljs didn’t like that WARNING: Use of undeclared Var styles.card/require at line 6
then i tried
(ns styles.card
(:require [garden.units :as u]
[styles.colours]
[styles.spacing]
#?(:clj [garden.def :refer [defstyles defrule]]))
#?(:cljs (:require-macros [garden.def :refer [defstyles defrule]])))
i don’t get any more errors
but also
styles.card
no longer appears in the list from clojure.tools.namespace.find/find-namespaces-in-dir
Not too familiar with reader conditionals, but seems like you need to wrap and then splice the clj branch
Plus I think you still need to require the namespace for cljs? (Crossing my fingers here...)
@iku000888 i can use defstyles
in this file and then prn
the result of that in the browser
so at least the cljs side of things seems to be working ok
actually i can also require styles.card
in clj and prn the result of defstyles
there too
so i can use the macros in styles.card
just fine in both clj and cljs
it’s just that when i run
(prn (clojure.tools.namespace.find/find-namespaces-in-dir (
every namespace except styles.card
appears
I would then try to debug the ns form with (read-string {:read-cond :allow} "ns form as string" ) in both cljs and clj
oh ok, i haven’t done that before
i’ll try that
gotta duck out for a bit
thanks for the tip though
i’ll let you know how i go 🙂
Hey, I wanna test some cljc code but I think I have the structure wrong. For example this simple test fails
(ns ns-test
(:require-macros [cljs.test :refer (is deftest async)]
[cljs.core.async.macros :refer [go]])
(:require [cljs.test :as test]
[cljs.core.async :refer [<!]]))
(defn adder
[]
(go (+ 2 3)))
(deftest test-get-stats
(async done
(go (is (= (<! (adder)) 5))
(done))))
So yeah what am I missing? I’m reading https://github.com/clojure/clojurescript/wiki/Testing
No error, just says test failed
(ns milia.api.submissions-test
(:require-macros [cljs.test :refer (is deftest async)]
[cljs.core.async.macros :refer [go]])
(:require
[cljs.test :as test]
[cljs.core.async :refer [<! >! chan take!]]))
(defn test-async
"Asynchronous test awaiting ch to produce a value or close."
[ch]
(async done
(take! ch (fn [_] (done)))))
(deftest test1
(let [ch (chan)]
(go (>! ch "Hello"))
(test-async
(go (is (= "Hello" (<! ch)))))))
Not familiar with core.async, but [cljs.test :refer (is deftest async)] should be [cljs.test :refer [is deftest async]] ?
@urbanslug the (done)
is called before the is
executes
Some answer on SO says "Tests are executed synchronously, so if you go async the test-runner won't. In Clojure you need to block the test runner via <!!, in ClojureScript you have to return an async test object. "
(deftest test1
(async done
(let [ch (chan)]
(async/put! ch "Hello")
(go (is (= "Hello" (<! ch)))
(done)))))
hmmm I don’t see what you did so differently from this
(defn adder
[]
(go (+ 2 3)))
(deftest test-get-stats
(async done
(go (is (= (<! (adder)) 5)
(done)))))
@iku000888 not sure how to get read-string
working in the way you suggest in cljs
but in clj:
(read-string {:read-cond :allow} "(ns styles.card
(:require [garden.units :as u]
[styles.colours]
[styles.spacing]
#?(:clj [garden.def :refer [defstyles defrule]]))
#?(:cljs (:require-macros [garden.def :refer [defstyles defrule]])))")
results in
(ns styles.card (:require [garden.units :as u] [styles.colours] [styles.spacing] [garden.def :refer [defstyles defrule]]))
which seems fine
(ns milia.api.submissions-test
(:require-macros [cljs.test :refer [is deftest async]]
[cljs.core.async.macros :refer [go]])
(:require [milia.api.submissions :as sub]
[cljs.test :as test]
[cljs.core.async :refer [<! >! chan put! take!]]))
(deftest test1
(async done
(let [ch (chan)]
(put! ch "Hello")
(go (is (= "Hello" (<! ch)))
(done)))))
btw I gave up and ended up asserting the type https://github.com/onaio/milia/blob/48ce90f7a7b070228c60ff9f8bfea1381218b5f6/tests/cljs/milia/api/submissions_test.cljs
(deftest test1
(let [ch (async/chan)]
(async/put! ch "Hello")
(async done
(go (is (= "Hello" (<! ch)))
(done))
)))
@thedavidmeister http://stackoverflow.com/questions/20046717/clojurescript-reader-read-string-returns-null
Apparently you need to explicitly require cljs.reader to use the read-string function
(cljs.reader/read-string "(ns styles.card
(:require [garden.units :as u]
[styles.colours]
[styles.spacing]
#?(:clj [garden.def :refer [defstyles defrule]]))
#?(:cljs (:require-macros [garden.def :refer [defstyles defrule]])))”)
@thedavidmeister cljs.reader
does not support conditional reading
Error: Could not find tag parser for ? in
...
but even so, as i’m running (prn (clojure.tools.namespace.find/find-namespaces-in-dir (
in clj, does it matter?
@thheller for some reason the #?
stuff in my cljc ns is causing the ns to not appear when i run clojure.tools.namespace.find/find-namespaces-in-dir
@thheller can you paste your code?
(ns styles.card
(:require [garden.units :as u]
[styles.colours]
[styles.spacing]
#?(:clj [garden.def :refer [defstyles defrule]]))
#?(:cljs (:require-macros [garden.def :refer [defstyles defrule]])))
like that?
yeah it is
i’m now wondering if the garden boot task is doing something...
(clojure.tools.namespace.find/find-namespaces-in-dir ( "src/main"))
=> (styles.card)
@thedavidmeister: do you have an explicit dependency on clojure?
If not it might be possible that the pod the garden task uses ends up loading a different clojure version
i added clojure in my dependencies, yeah
1.8.0 btw
nah i don’t think it’s the garden boot task
i did this
(deftask garden
"Wraps the garden task provided by boot-garden"
[p pretty-print? bool "Pretty print the CSS output."]
(comp
(watch)
(with-pass-thru [_]
(require '[styles.compile])
(styles.compile/foo))))
(ns styles.compile
(:require [garden.core]
[clojure.tools.namespace.find]))
(defn foo []
(prn (clojure.tools.namespace.find/find-namespaces-in-dir ( "src/cljc"))))
(styles.animation styles.border styles.box-model styles.box-shadow styles.colours styles.compile styles.neat styles.spacing styles.typography)
no styles.card
😞
@martinklepsch on a side note, i don’t really understand the pods thing. What is it doing for the garden task?
@thheller what version of clojure are you using?
Have to go now but basically it helps isolate dependencies by providing a construct "pod" that can have a different classpath than the rest of the application
i’m thinking i want my garden to sit alongside my application
maybe that’s wrong
@thheller so weird
i tried with boot repl
is there another way to get a repl that might find it?
oh i can require it just fine
i checked that i can require it and prn the output of defstyles in both clj and cljs
if I see that right (styles.animation styles.border styles.box-model styles.box-shadow styles.colours styles.compile styles.neat styles.spacing styles.typography)
well that has the same issue
(ns styles.breakpoints
(:require [garden.stylesheet :refer [at-media]]
[garden.units :as u])
#?(:cljs (:require-macros [styles.breakpoints :refer [defbreakpoint]])))
#?(:clj
;
(defmacro defbreakpoint [name media-params]
`(defn ~name [& rules#]
(at-media ~media-params
[:& rules#]))))
any file i stick the cljc reader thingo into the ns for disappears from the list
(ns styles.breakpoints
(:require [garden.stylesheet :refer [at-media]]
[garden.units :as u]))
; #?(:cljs (:require-macros [styles.breakpoints :refer [defbreakpoint]])))
#?(:clj
;
(defmacro defbreakpoint [name media-params]
`(defn ~name [& rules#]
(at-media ~media-params
[:& rules#]))))
boot.user=> (prn (clojure.tools.namespace.find/find-namespaces-in-dir ( "src/cljc")))
(styles.animation styles.border styles.box-model styles.box-shadow styles.breakpoints styles.colours styles.compile styles.neat styles.spacing styles.typography)
i can use #?
in the file
but not in ns
not sure how to do that
i can set a dependency though
what version are you using?
actually it does look like ring depends on [org.clojure/tools.namespace "0.2.10”]
[org.clojure/tools.reader "1.0.0-beta3”]
omg that worked
boot.user=> (prn (clojure.tools.namespace.find/find-namespaces-in-dir ( "src/cljc")))
(styles.animation styles.border styles.box-model styles.box-shadow styles.breakpoints styles.card styles.colours styles.compile styles.neat styles.spacing styles.typography)
hopefully it’s an upgrade in tools.namespace
and not a regression in tools.reader
...
i’ll check
so i think it was just a bug in 0.2.10
in fairness, this is probably the first thing i should have tried
i just assumed i was doing something wrong in cljc
this is the first time i’ve used cljc
all this so i can pass my data from garden to js libs 😛
Hi! I am new to clojurescript (and clojure). I'm trying to work out an architecture for an isomorphic web app (clojure back-end). I know there are some examples of server-rendering in reagent. Examples aren't so good for rum because it's unopinionated. That's one issue. The other is how to handle CSS. There are some suggestions out there to use sass, but that's not enough. What about autoprefixer, removing unused CSS, etc.? It seems like there aren't any lein or boot tools for this yet. Is my only option to use node for post-processing CSS?
I don’t understand the output of (type #js [1 2 3])
:
#object[Array "function Array() { [native code] }”]
I'm new to CLJS, so I'm not sure what the hash means, but "Array" is the right constructor. The 2nd part looks like a string representation of the Array constructor in JS. "[native code]" is binary code.
@borkdude type in cljs gives you the constructor of the object. in your case that is the Array function which is native code
cljs.user=> (source type)
(defn type
"Return x's constructor."
[x]
(when-not (nil? x)
(.-constructor x)))
@borkdude you might be looking for goog/typeOf
cljs.user=> (goog/typeOf #js [])
"array"
Unsurprisingly Closure dominates load time and run time against all other JS tooling as project complexity increases
@keeds probably file a bug - you should be able to reproduce this on js/String
though, I would leave anything that involves a browser out of the issue
When dealing with cljs/js interop and libraries that use this-context method chaining, what’s the best way to invoke that from cljs? for example:
someLibrary(a_div).doSomething({ args: true}).doAnotherThing()
Internally someLibrary utilizes a lot of if (this.foo)
where the initial object constructed by someLibrary(a_div)
binds the this.If I try a thread macro the this context always comes up null/undefined, which I assume is due to the rewriting of the macro not knowing/caring about this?
My other suspicion is that perhaps I'm misusing closure’s object.get, expecting it to do something it’s not…
(-> (js/someLib node)
(#((oget % "foo") (clj->js {:some :args})))
(#((oget % "on") "resize" (clj->js {:some :more-args}))))
(.. x …)
is just repeated method calls using each preceding return value as the first argument
@dnolen FWIW I can repro with js/String
in 1.9.293:
cljs.user=> (extend-type js/String ISeqable (-seq [x] x))
⬆
WARNING: Extending an existing JavaScript type - use a different symbol name instead of js/String e.g string at line 1
#object[Function "function (x){
var x__$1 = this;
return x__$1;
}"]
cljs.user=> (first "asd")
No protocol method ISeq.-first defined for type object: asd
@anmonteiro try it with a custom protocol
aha... sugar gave me semi-colon cancer? I’ll have to investigate how ..
handles advanced compilation to avoid munging issues, but thanks for the tip @dnolen ~
the only time you should ever be thinking about advanced compilation is when you’re including some random JS library
I was hoping to use object.get and object.set and strings to avoid having to write an externs entirely
a custom protocol works.. still don't understand why the above wouldn't?
since I’m only using a tiny piece of the library, and a complete externs is a much larger committment
@anmonteiro well there’s our bug 🙂
FWIW it doesn't work on 1.9.229, so I could also be doing something wrong
@lwhorton if you’re writing an app and you’re not publishing something who cares how complete your externs are
eventually we will automate what we can - but it’s really not that hard to write a couple of line for whatever you are using from some random library if that’s all you need
@anmonteiro the issue as @keeds reported it is really a red herring anyway
@anmonteiro if this is failing it’s most certainly going wrong at satisfies?
or implements?
should (extend-type js/String ISeqable (-seq [x] x))
work though?
@anmonteiro yes it should
I think it should, but there could be something preventing that
but at least we know some things are working and others aren’t - which is a bit more information
this is what I did for transit-js, value
and done
weren’t in the Google Closure externs yet for the JS Iterator stuff
I’ve never seen an externs operate directly on Object.. always some variable = function () {}; variable.prototype.foo = ...
that must mean you can use a callback fn that’s handed a transit object and (.-tag/rep/done/etc. obj)
becomes un-mangled (or rather never mangeld)?
if you put a property on Object, then when Closure sees a property with that name and infers type Object, it knows not to rename
A counter point could be that when you set some arbitrary wire-related externs on Object it can bite you a few months later when you forget about it and start wondering why some arbitrary names do not get renamed in advanced mode in cases where you would expect them to. It can be pretty hard to track down if such externs are bundled in some library or otherwise hidden from plain sight. There is no tool which would tell you “this happened because of Y”, at least I’m not aware of any.
the real solution is everyone should stop using javascript and write everything in cljs from here forward, obviously
the more people keep conflating the reasons for this stuff the longer everyone stays collectively in the dark
but you have to know it, you have to know, that the object you are passed is “external data” so you should use string names to access its properties, the line can be pretty blurry here
speaking about it this way also has wider implications even when we get externs inference
but still, I’m afraid, this sounds all clear and easy to you and me, but newcomers really struggle to distinguish these nuances without deeper understanding how closure compiler, javascript and clojurescript work
@darwin sounds like a guide worth writing for http://clojurescript.org for someone who is willing 🙂
your word choice makes me think this is work under way with the compiler? that will be exciting
@lwhorton there’s some prototype work I got started on and it will probably happen relatively soon
Hello everybody, anyone know of a decent logging library that works for both clojure.tools.logging
in JVM Clojure and (.log js/console)
in browser-based ClojureScript?
timbre has adapters for c.t.l
and works in browser
@timgilbert Google Closure also has one if shared logging isn’t a goal
Oh, interesting, will look at that
Not sure if timbre will work or not, but I'll give it a look too
@timgilbert I started working on one, but my goal is not to make it 100% compatible, I will just mimic clojure.tools.logging api in cljs and make it cljs-devtools friendly, e.g. it will use pprint in advanced mode (if not elided)
@timgilbert if you have ideas to share, I would like to hear them - I’m still not 100% sure how I want to approach it, want something like https://github.com/adzerk-oss/cljs-console, but without string printing, and api similar to clojure.tools.logging
, in dev mode it would just boil down to console.log calls, in advanced mode some or all log levels can be elided and those which are not would be presented with pprint or similar alternative code-path
also I want to support formatting from devtools, but in a different way, not inheriting inflexible C-format strings which don’t compose
That all sounds great @darwin. Right now I'm using shodan and its killer feature is that it uses macros, so that the log statements in the console all point back to the line in the actual source file where the log statement was, instead of all pointing to some line of code in a library somewhere
@timgilbert yes, I will support that as well
Personally my use-case is that I have a fairly small set of cross-platform code that I need to call from both Clojure and ClojureScript, and I'd like to be able to minimize the amount of #?(:clj :cljs)
blocks in there, to zero if possible
Right now I'm looking at just writing a thin macro layer, which isn't hard to do but I thought I'd check if something already existed first. I did look at timbre briefly but some other folks on my team seem to dislike it