This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-02-08
Channels
- # aatree (3)
- # announcements (1)
- # architecture (5)
- # beginners (27)
- # boot (22)
- # cider (17)
- # cljsrn (8)
- # clojure (93)
- # clojure-canada (1)
- # clojure-dev (7)
- # clojure-nl (10)
- # clojure-poland (216)
- # clojure-russia (35)
- # clojurescript (163)
- # community-development (6)
- # cursive (25)
- # datavis (6)
- # datomic (18)
- # dirac (10)
- # dysphemism (4)
- # editors (3)
- # editors-rus (1)
- # emacs (15)
- # hoplon (124)
- # instaparse (25)
- # jobs (10)
- # ldnclj (78)
- # lein-figwheel (11)
- # leiningen (6)
- # off-topic (20)
- # om (149)
- # onyx (2)
- # parinfer (5)
- # portland-or (1)
- # proton (62)
- # quil (2)
- # re-frame (8)
- # spacemacs (4)
- # yada (20)
Is there any global way to change how functions are printed with pr-str? The default way of printing out the javascript implementation isn't really helpful for my needs. From looking at the source, you could potentially override IPrintWithWriter, but there isn't really a specific function type that you can extend for just functions. There does seem to be the ability to give pr-str an option map where you can change the implementation, unfortunately, in my case, there is an external library that is making the pr-str call that I can't control.
@taylor.sando: There was a recent discussion with the conclusion “no; it would be a low priority to add that” but at the same time a note was made that extending IPrintWithWriter
to js/Function
seemed to work (even though you are not supposed to do that)
(extend-protocol IPrintWithWriter
js/Function
(-pr-writer [f w _] (-write w (.-name f))))
That works. If you just call it function, instead of js/Function it won't throw this warning: WARNING: Extending an existing JavaScript type - use a different symbol name instead of js/Function e.g function
which according to my understanding of the docs is done thusly: (f/parse (f/formatter "HH:mmA") (t/now))
But parse
seems to expect the 2nd parameter (the date object) to be seqable and it's not in every different format I've tried
@taylor.sando: For me, in bootstrapped ClojureScript, I'm finding that extending to js/Function
works, but not to function
.
Ya I just tried it again. It was because I was using boot's reload. It was still using the js/Function instance
@samueldev: Doesn't it parse a string (which can have seq
applied to produce a seq of characters) rather than operate on a date object?
@mfikes: that's tha path I went down but then if I simple wrap the (time/now)
call in (str)
, no dice
Unless there's some library fn to convert it to a string in a very specific way which I'm unaware of
@samueldev: that's my guess ^ but I haven't used it
@samueldev: you want f/unparse to get a formatted string from a date
I'm trying out cljs-ajax for the first time, and when I post and check the network tab on firefox I see this: ["^ ",":email","test.c",":password","cool"] - how do I force it to post in a clojure-friendly map so my backend can talk to the client?
@datran: looks like you want to specify :format
if you want something other than Transit
@datran: don't know. There appear to be good docs here, recommending ring-transit. Probably just have to read up on it if someone here isn't experienced in it. https://github.com/yogthos/cljs-ajax/blob/master/docs/server.md
@mfikes Thanks! I'll explore a bit. I hadn't ever looked at transit before, so this should help.
@datran: Compojure-api has built-in transit support
Hello,
I read a tweet in the last days, about better support of clojurescript in google devtools, but can't find it anymore. Did some of you has a hint, what tool it could be?
@danielgrosse: perhaps #C0J01U7MY
@meow thank you
We’re using cljs-ajax for communicating with our transit-emitting backend. The backend is able to send out tagged literals such as ratios, but I’m having trouble understanding how to parse these on the frontend. @jaen wrote something about implementing a transit reader, but I’ve lost the concrete hints from that conversation
Here's how readers/writers could look -https://gitlab.com/jaen/clj-cljs-presentation/blob/master/src/presentation/common/utils/transit.cljc
@jaen: thanks! And these readers/writers are totally decoupled from which http client I am using, right?
@grav: and then you can use it with cljs-ajax somewhat like here - https://gist.github.com/jaen/7414aebdebf43af8f80a - just be sure to verify with the docs, this code has about a year.
@grav: if something doesn't work you could check read-handler
and write-handler
docstrings, but they are fairly mysterious and need understanding the relevant spec parts.
@grav: my current handlers look like this - https://gist.github.com/jaen/471319bd8c4c4bc739ce; as far as I understand the first arg to write-handler
is a function that returns a tag, second function is a function that returns a representation that can be any of basic transit types (like number, vectors or such) and the third function returns a string representation; read-handler
is one function that gets a string representation.
The issue I was having I think, was that JSON transit worked with my previous handlers definition no problem, but msgpack transit broke - it didn't know how to serialise a Date object (JSON transit probably just either stringified or was using the other definition).
Yeah, I think that might be the case - that is msgpack using repr
function (second arg) and JSON using stringRepr
function (third arg).
I’m running ClojureScript 1.7.228 and system-time seems to not be defined. Does anybody know why?
cljs.user=> (system-time)
#object[TypeError TypeError: Cannot read property 'call' of undefined]
TypeError: Cannot read property 'call' of undefined
at eval (eval at figwheel$client$utils$eval_helper (), <anonymous>:1:110)
at eval (eval at figwheel$client$utils$eval_helper (), <anonymous>:9:3)
at eval (eval at figwheel$client$utils$eval_helper (), <anonymous>:14:4)
at figwheel$client$utils$eval_helper ()
and you are sure that this variable must be defined?
@mfikes: how could I improve the description of http://dev.clojure.org/jira/browse/CLJS-1565?
@viebel: a minimal set of exact steps and small file descriptions without downstream tooling. https://github.com/clojure/clojurescript/wiki/Reporting-Issues
@viebel: in this ticket a patch is attached and I'm curious if it fixes it for you. It might be related http://dev.clojure.org/jira/browse/CLJS-1541
@pupeno: I’m also on 1.7.228, and (system-time)
is working fine here. I wonder if this has something to do with Figwheel? Just a guess.
Though even with Figwheel, it’s working for me… so now I’m not so sure. I’m on 0.5.0-6 if that matters.
@mfikes the patch didn't fix the issue
@mfikes: what do you mean by "without downstream tooling"?
@taylor.sando: there could be a way, redefine pr-opts function in cljs.core, use :alt-impl to wrap default printing implementation and then post-process it in your wrapper
I do this in cljs-devtools, I provide my own implementation, which calls original implementation with own writer and then inspects its content and does some post-processing on it: https://github.com/binaryage/cljs-devtools/blob/master/src/devtools/format.cljs#L239 in my case I needed to revert stringification of javascript objects as “#object …” inside default implementation
@joelkuiper: I have used optimus for minifying and cache busting
What's a good (the official?) way to check for a js var that may or may not exist?
1. (try js/bla (except ..))
2. (when (exists? js/bla) js/bla)
3. (aget js/global "bla")
4. ???
Yeah, I’d say 2 as well. It’s also used in the ClojureScript source code quite a bit
@jaen: this is what I ended up with:
(def reader
(transit/reader :json
{:handlers {"ratio" (fn [[nom denom]]
(/ (-> nom
(.-rep)
(js/parseInt))
(-> denom
(.-rep)
(js/parseInt))))}}))
when I do an ajax request, I then use it the following way:
(ajax/GET
{:handler ...
:response-format (ajax/transit-response-format
{:raw false
:reader reader})
Hm, yeah, I think you can supply a whole reader as well, though I prefer to just supply the handlers.
Actually I think transit should have been able to handle ratios without additional handlers.
Btw - hwo do I find the “key” for a tagged literal? Eg ratios are “ratio”, and it seems BigDecimals are “f"
They basically are random - https://github.com/cognitect/transit-format#ground-and-extension-types
> I’m not sure I understand what you mean by “that’s not the case later”? Maybe I suck at sentence structuring, what I mean is that you can look at it at a later time, since it's working.
@darwin: This is what I came up with https://gist.github.com/taylorSando/c63b2c49bce0ff1107df
@taylor.sando: looks good to me, instead of cljs.core/pr-writer-impl you could use :fallback-impl in opts, in case this was chained (very unlikely)
where is the documentation for Clojurescript's this-as macro ?
it's not here https://github.com/clojure/clojurescript/wiki/Differences-from-Clojure
it's not here http://cljs.info/cheatsheet/
https://github.com/clojure/clojurescript/blob/master/src/main/clojure/cljs/core.cljc#L1285
a friendly recommendation: don’t be afraid to search and read cljs core, it is not that scary as it sounds
shouldn't have to - important features like that should be documented
@darwin - searching the source code doesn't count as reading documentation, sorry
the two links I posted should both have this-as clearly documented, as this feature is crucial for Clojurescript interop
in fact, Clojure's documentation is getting to be quite poor. In order to attract more people, documentation and examples are critical
I’m not the right person to really defend Clojure’s documentation here, I did exactly zero contribution to it, but
In general I agree that docs should be better, but it is not fair to blame random site on the internet to have poor cljs documentation (http://cljs.info is not officially affiliated AFAIK)
@darwin: errr, that's not a "random site", it's linked to from http://clojure.org/api/api
therefor is officially affiliated
@octo221: there’s an existing ticket to at least generate autodoc a la Clojure - anybody can take this one - definitely low hanging fruit and relatively newbie friendly
as far as high level documentation, the wiki is definitive and lot of effort has gone into it
@dnolen: are you suggesting I go generate the documentation myself ?
because I was searching for it for a friend who's new to Clojure
autodoc just needs small tweaks to be able to handle ClojureScript source - then we can setup automation and publish it to a sensible location
it really annoyed me that I could send him a link
couldn't
I’m sure @alexmiller would help out if the the autodoc bit was sorted out
@dnolen: well, exactly, this is LISP - there's no excuse for lack of documentation when we can generate it from the source
but in general we need more example code, to welcome newbies to the language
not just for newbies, for everyone, as we forget
what’s missing is just base level API documentation, somebody can chip in a medium sized task and have a big impact
I’m sure there would be an avalanche of docstring improvements as well once we got that going
I was under impression that @shaunlebron is working on it here: https://github.com/cljsinfo/cljs-api-docs
generated this-as doc page could look like this: https://github.com/cljsinfo/cljs-api-docs/blob/catalog/refs/cljs.core/this-as.md
@darwin @dnolen you know what would be really cool, is if ALL Clojure functions & macros included a simplest-possible example of usage, in their source -- like :example '(this-as this ...
@octo221: that specific request is unlikely to happen in the docstrings themselves, at least not without further discussion, and there are already existing community efforts that provide stuff like that and more
@dnolen: I mean in the function's meta map
ClojureScript just follows Clojure conventions here, if people want to see some different thing adopted then start a discussion - but note that’s usually a involved process with lots of consideration
Does anyone know how to profile the cljs compile time? My whole project takes 17 seconds to compile, and when I specify 0.2seconds:recompile-dependents false
it drops to
so I'm trying to figure out if I can change my ns dependencies to allow recompiling dependents, but not take more than ~5 seconds to compile, since I'm using figwheel for hotloading
Where would I go to see how a symbol in ClojureScript (like foo-bar.baz/quz
) maps to a JS name (like foo_bar$baz$qux
)?
hello guys, when Figwheel displays "Page not found" what usually can be the problem?
the log is empty here...
@peeja foo-bar.baz/quz
would be foo_bar.baz.quz
, the other name is just the local name and pretty much irrelevant
https://github.com/paulirish/The-cost-of-transpiling-es2015-in-2016 yay for closure compiler!