This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-12-12
Channels
- # admin-announcements (1)
- # bangalore-clj (13)
- # beginners (149)
- # boot (123)
- # cider (7)
- # clojure (167)
- # clojure-brasil (3)
- # clojure-greece (1)
- # clojure-korea (2)
- # clojure-new-zealand (2)
- # clojure-russia (70)
- # clojure-sanfrancisco (3)
- # clojure-spec (84)
- # clojure-uk (36)
- # clojurescript (300)
- # code-reviews (242)
- # community-development (34)
- # core-async (4)
- # css (1)
- # cursive (37)
- # datascript (1)
- # datomic (20)
- # defnpodcast (1)
- # dirac (15)
- # events (7)
- # garden (12)
- # hoplon (100)
- # lein-figwheel (11)
- # off-topic (2)
- # om (69)
- # om-next (3)
- # onyx (86)
- # planck (14)
- # proton (4)
- # protorepl (1)
- # quil (2)
- # re-frame (53)
- # rum (3)
- # untangled (1)
- # vim (50)
@rauh Nice work!
@flyboarder my 2c - i think that the article suffers by being a series of inline responses to the body of the original how-it-feels-to-learn-js-in-2016 post. makes it feel a bit disjointed and a bit difficult to read IMO. i think you might be able to make your argument much better if it were written in the form of a regular post/article/essay/etc rather than as a series of quotes/responses - also this way you wouldn’t have to repeat yourself quite as often, since you’d be controlling the bits of the essay and the order that they appear in. hope this is helpful 🙂
@jrheard thanks for the suggestion, I will probably go back and remove some of the inline stuff.
@puppybits I like this part: ClojureScript core.async is like the green wrap tubes in Super Mario Bros
🙂
Minor typo with wrap
vs warp
@puppybits i’m leaving you some edits/comments
@wildermuthn @meeli Thanks a ton for reviewing it. I'm rereading through it now to clear up spelling/grammatical errors.
@meeli Thanks for the feedback. It feels so much more polished with your recommendations. I really appreciate it.
Here's the live link: https://medium.com/@puppybits/how-javascript-fatigue-simplifies-coding-and-increases-revenue-46925c7efd47#.nywen158d
in Clojurescript, why can't i use fns defined in a .clj macro namespace from a .cljs namespace ?
(i can only use macros defined in the .clj macro namespace, not functions)
@octo221 I believe you can if you rename the file to .cljc
. You'll need to use reader conditionals for stuff not available in ClojureScript.
Ever wanted to use goog enums in a case
? Here you can generate a NS so that you can: https://gist.github.com/rauhs/098a720669c75e53eb00dc3e6ed58e49
does anybody have an css trick up their sleeve for avoiding to style js libs within cljs. Then I mean when a library gives you endpoints like nestedListStyle
titleTextStyle
etc, any css function available that I could simply say :nestedListStyle #js { extend everything from class x}
?
@rauh seems like this might be a nice optimization language-wide, think there's a way to do that?
@martinklepsch Doubt it, you first need to eval javascript to get the objects in question, walk and filter them. Then output something to the compiler, which can only be done during macroexpansion.
@rauh would it work if goog.events.KeyCodes
had a ^:const
annotation?
@rauh not thinking in terms of writing some macro but rather enhancing the Closure<>CLJS integration for all of CLJS in this way
No the clojurescript compiler wants a var with a :const
metadata to allow case constants
I think the problems will be that clojurescript can't really analyze google closure (js) code.
There is a potential for a new clojurescript construct that allows much more flexiblity in the case:
constructs, but I doubt that'd be considered since Java is less flexible and then we'd brake clojure<->cljs compatibility
If the conditions are expensive that wouldn't end up being more optimal would it?
I mainly wanted it for readability and multiple case constants: (case x (ENTER ESC ALT) (doit))
Yeah, totally agree that that's nice
how to require and use an npm module inside clojurescript? i found https://github.com/RyanMcG/lein-npm this but it talks about things i don't want to do, and it doesn't talk about the thing i want to do
I'm trying to use core.async in nodejs but a (go (>! c 5))
throws a Could not resolve var >! error, more info here - http://sprunge.us/LiJI . What could be the reason? I have cljs 1.9.293 and async 0.2.395 as dependencies
if I do (put! c 5)
and then (go (println (<! 5)))
I even get Could not resolve println
, which is kind of funny
when i decided to try clojurescript, i believed that interop with javascript is beyond the most obvious let's just put properties on the global variables and let's hope nothing overwrites them...
this is ridiculous to say the least https://groups.google.com/forum/#!topicsearchin/clojurescript/npm$20AND$20browserify/clojurescript/l4IaLlfUMIs
not even an answer? so questions that are not interesting to the community are ignored everywhere, this really shows the experience i am living right now, where i feel that i was told a lie so many times i believed it
@ashnur not many people use cljs on top of nodejs. As you can see from my question above I'm having similar issues. It's not that questions are ignored, there just aren't many people that could give an answer
why do you think i am using it on nodejs? i am not and i never talked about using it on top of nodejs
@ashnur I figured the web modules are mostly covered with https://cljsjs.github.io/
and when i say ignored, i mean that for weeks i've been asking questions regularly on several channels on this slack and the weather is more reliable than trying to get help
and i see many people asking the same questions and being left unanswered by the "community"
telling the OP that their solution is a hack and not a good idea in general perhaps unless they don't plan maintaining the code
noone's gonna answer a 1yo question today. And that question is from Dec 25th and he kind of answered his own question
i know, and it also doesn't have a lot of other stuff that node has, again, as i mentioned before, i don't care about the API dependent stuff because I don't use it, I don't need the node.js require, i need whatever require to load the dependency.
the whole JS world can't even decide how to do things ... given npm
, yarn
, webpack
, browserify
, ...
when their own ecosystem can't even deal with anything that's not dumb as js menu from 1997
@ashnur You'd do well listening to thheller, there is less than a handful of people who know the cljs build system better than him. That being said: Just include your library in a <script>
tag and use it in cljs. That's as easy as it gets. Once you want to do advanced builds you'll have to supply an externs file so the minifcations leaves those fields alone.
using html to manage project dependencies is a no go, i am not going back in time 10 years just to accommodate clojurescript quirks
That'll get you started to use the library, nothing wrong with that. If you want to compile it all in once you just do an npm install
of you library and use :provides
compile option
Some examples: https://github.com/search?utf8=%E2%9C%93&q=node_modules+provides+extension%3Aclj&type=Code&ref=searchresults
This is a solution to your problem. If there is something specific why that's not good enough, then you'll have to ask a specific question.
i just want to use this jsnetworkx from clojurescript without having to manually wrap it, expose it, include it in a script or anything. i want a solution that is not unique so if someone who understands the tooling knows what's happening and they don't have to read my configuration code to figure out what i did. i definitely do not want to touch html, beyond including the basic template with a single div#app that i will populate from reagent.
someone should've given me this link when i first asked about this topic https://github.com/clojure/clojurescript/wiki/Packaging-Foreign-Dependencies
It is very much expected that somebody who used clojurescript clicks on "Get started" on the official http://clojurescript.org homepage. Where there is a section about "dependencies" and links to more details.
@ashnur: your tone definitely doesn't help anyone willing to answer your question(s). Apart from that, I think you need to adjust your expectations. Every technology has tradeoffs. ClojureScript has used the Google Closure Compiler since its inception which means it has chosen to accept the tradeoffs it imposes (specifically that it hasn't historically been easy to consume random JS libraries, either from NPM, bower or whatever package manager or module system of your choice)
That said, there's work underway to make that integration easier
The JS module consumption is already in the ClojureScript compiler, but should be regarded as an alpha feature
Unfortunately I don't think there exists a lot of docs on that apart from Maria Geller's blog posts and a Lambda Island screencast
sorry about my tone, i am not raised in California and if people act as they are helping while they are actually working on making me angry, they will succeed easily.
@ashnur this is the screencast I talked about: https://lambdaisland.com/episodes/javascript-libraries-clojurescript
If it helps answer your question consider buying a subscription (I'm not affiliated with it in any way). At the least, give a warm "thank you" to @plexus for taking the time to make it available for free
@deas: no you'll need to use master
since there's a few more people talking now than when I asked. Any tips on my question from 2 hours ago? I can't get core.async to work with nodejs. I tried several versions of cljs and core.async by this point and nothing worked
@xifi did you (:require-macros [cljs.core.async.macros :refer [>!]])
?
Or is >!
a function? I can't remember at this time
I think >!
is a function
Anyway you need to require the macros namespace as well as the cljs.core.async
namespace
https://github.com/clojure/core.async/blob/master/src/main/clojure/cljs/core/async.cljs#L108
@anmonteiro function. The same code worked on top of the JVM
go
is definitely a macro
Don’t you need to require cljs.core.async
?
Oh lol I am duplicating @anmonteiro
you should be getting a warning, something about go
missing? or maybe you are using the go
macro from clojure?
so the namespace is different in clj and cljs? This is what I tried to do http://sprunge.us/IYSB
as @anmonteiro said it must be cljs.core.async.macros
not clojure.core.async
`(require-macros [cljs.core.async.macros :refer [go]])`
for cljs you should always use cljs.core.async
and not rely on clojure
-> cljs
aliasing
@deas :infer-externs
is experimental - people need to kick the tires with master first
@dnolen really hard to assume that with strawmans and false dilemmas thrown at me 😞 i hope you understand that
if i want to help someone i try to understand them and not act if they are somehow stupid because they don't already know the limitations of my system
@ashnur back on topic. Integrating seamlessly with npm modules is just not a goal and it’s never going to be. So you should expect some friction there since it’s just not something we’ll ever prioritize. All this goes back to how Google Closure works - fundamental tradeoff.
so your frustration are just a reflection of choices that were made long ago and they are not going to change. If you don’t like it, don’t expect us to do anything about it.
that said, there’s some work in to consume node_modules directly coming to the Closure compiler.
it looks promising - but it still won’t ever address the fundamental problem - most libraries can’t go through advanced compilation.
they usually provide a minified thing in the JAR, these all get concated in dep order and preprended to the final build
Would it matter in lookup speed if I used vectors (of numbers) as keys or (str […])
them first in ClojureScript hash-maps?
@borkdude I don’t recommend doing that, but if you have some inner loop then you could try to measure
this is the kind of thing that you should probably expect to see some large variance across JS engines
Is there a way to tell that a parameter (a function) can be called static (ie without .call(null, ...)
? I'm currently resorting to (js* ...)
macro to do that in performance critical code.
@rauh I assume :static-fns true
isn't helping you?
Hey all, the 2016 State of Clojure Community survey is now open! We do this every year as a way to take the pulse of the community and if you can spare 5 minutes to take it, it would be awesome to get input from everyone here. https://www.surveymonkey.com/r/clojure2016
@rauh as you probably know don’t use js*
, since no promises it will work in the future. .call
is avoided when possible even in higher order cases.
@rauh we never just do call
if we can avoid it, we’ll check if there’s is an arity we can invoke directly first.
@dnolen But in case of an argument, how could this .call
ever be avoided? (Like (defn f [cmp a b] (cmp a b))
Well I'm changing a bunch of the datascript code to optimize some things. The comparators are heavily invoked.
this is why higher order stuff can be ridiculously fast, like @mfikes C comparison post
yes I do not recommend hacking around perf stuff, there’s 5 years of work in this stuff already
even if you erased it you would (potentially) have to go through the fn’s arity dispatcher and performance would go down the toilet
Yeah in that particular case, the comparators only have one arity, but I agree, my optimizations all in a sudden make no sense. So I'm reverting
@rauh right so there’s the one place where we potentially lose, one arity higher order invoke
Still keeping my datoma.a.fqn < datomb.a.fqn ? ...
comparator though, which was a nice speedup.
@dnolen I want to know, how atom and watchers work. How they implemented in js. Did you use observers to implement the atom watchers functions ?
@lxsameer but hardly anything in ClojureScript is implemented in JS 🙂 no we don’t use observers, it’s just some custom ClojureScript.
@lxsameer https://github.com/clojure/clojurescript/blob/master/src/main/cljs/cljs/core.cljs#L4228-L4255
is there a shorthand in clojurescript for repeatedly setting properties on an object?
@borkdude for a javascript object?
I have:
(set! (.-strokeStyle ctx) "#1f77b4")
(set! (.-fillStyle ctx) "#2C82C9")
(set! (.-lineWidth ctx) 1)
you could use extend?
using goog.object/extend
would be way nicer already
(gobject/extend ctx #js {:strokeStyle "#1f77b4" :fillStyle "#2C82C9”})
I have a project which requires a decent amount of custom html / js for testing, and I was hoping to use Hiccup and Reagent. In general, when I’ve used Reagent or any ClojureScript setup, I’ve used something like Figwheel to constantly recompile the ClojureScript, but is there anything more along the lines of an include-cljs
function in Hiccup, or a different way to get them to play together nicely? i.e. I don’t really want to precompile the ClojureScript, because it will only be used in testing, and only with very small files, but I’d like to be able to say something along the lines of:
(html5 {:lang "en"}
[:head
[:title title]
(include-css "//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/css/bootstrap-combined.min.css")
(include-cljs “my-ns.example1”)
[:body
[:div {:class "container"} content ]]]))
@surreal.analysis in the past people would sometimes compile on demand via a webserver that runs ClojureScript
So that’d be just having a webserver that called cljs.build.api/build
on demand?
Hello everyone! I stumbled upon this great article on core.async in clojurescript: http://rigsomelight.com/2013/08/12/clojurescript-core-async-dots-game.html I believe it is previous to om, reagent, etc., and the author himself warns "take my Clojure idioms with a grain of salt" I find the approach very interesting thou, in that state is not managed via a global atom, but with channels, so it "flows" to where it is needed without needing anything global (from what I understand) I wonder what experienced people think of this pattern 3 years later... Is it a good way to develop more complex apps? Does it make it easier or harder to test, troubleshoot, debug, etc (compared to om.next or reagent, for instance)?
@jalvz in the small, those functions that just operate on a channel appear nice and concise, you can view them with predictable ins/outs from a channel perspective. But in the large, the state of that game is some timeline of channel puts and gets and side affecting function execution, so 'where is the bug' is harder than a global state management where you know where the truth is at all times... i.e. why the frameworks use async stuff, but they return data and manage state uniformly rather than sprinkling it all over
@jalvz I actually worked on a large scale project that used messages, core.async and separate atoms for every control. So when you click a button it sends an "event" to it's parent, and the parent's parent until something does something with the message. Sounds fantastic...and it was utter hell.
My opinion is now...the less mutable "things" in your gui the better.
The benefit of using #js
is primarily compile time so you don’t have an allocation overhead, right?
Here it says: function/macro, kind of confusing 🙂 https://cljs.github.io/api/cljs.core/js-obj
@borkdude more context on function/macro: http://blog.fikesfarm.com/posts/2015-12-12-clojurescript-macro-functions.html
thanks! I wondered about this because if I would write a function like:
(defn set-properties [obj props-map]
(gobject/extend obj props-map)
obj)
and I would pass a map to it with #js, like (set-properties ctx #js {:foo 1 :bar 2})
, the ClojureScript map will never see the light of day at run time right?
But what if I would make it more convenient for the user and write:
(defn set-properties [obj props-map]
(gobject/extend obj (js-obj props-map))
obj)
and call it like:
(set-properties ctx {:foo 1 :bar 2})
@dnolen well, this function basically calls goog.object/extend, which expects a javascript object instead of a clojurescript object. But if I wrap that in a function because extend annoyingly doesn’t return the object and to allow the user to call this function with a normal clojurescript map, can I prevent the overhead of the clojurescript map at run time.
it’s good enough, but you still have to write #js. No problem, this can be solved with a macro.
@borkdude sounds like your problem is just with the #js
syntax then?
My cljs REPL:
(doto ctx (gobject/extend #js {:x “bar”}))
;; prints {:x “bar”}, but returns the `ctx`
@anmonteiro well, I was wondering about how this would be optimized, but I guess I can just write a macro to be sure of this
I don't really understand what the problem is though
your approaches all seem equal to me in that you always end up calling gobj/extend
(disregarding stuff like clj->js
etc)
cljs.user=> (doto #js {:a 1} (gobj/extend #js {:b 2}))
#js {:a 1, :b 2}
^ this should be what you want, as David mentioned
@anmonteiro yes, my question was like this: suppose you want to make a 1) function (not a macro) that calls gobj/extend for you and 2) this function accepts normal clojure hash-maps, in which cases will this hash-map be optimized away. My assumption is not at all, because the function argument is not a literal.
"not at all" seems right to me
We’re using Reagent. Turns out it has a macro which is pretty nice in this case:
(doto #js {:a 0} ($! :b 1) ($! :c 2) ($! :d 3))
hello everyone, I just noticed that cljs doesn’t intern keywords. does anybody know why and how can it impact a memory traffic?
since those don’t exist, we don’t intern - I don’t really understand the later half of your question
@dnolen I mean it can produce a major memory pressure. did anybody try to intern them just by hard refs and see if allocation profile gets better?
@jetzajac I’ve never heard anybody report memory pressure issues around this in 5 years
but to avoid allocations for keyword literals we do dump a constants table of keywords under advanced compilation
so, what is your suggestion to my problem? I need a random graph generator, should i try to implement one or try to use one from javascript, which is the recommended way? 🙂
@ashnur what’s wrong with jsnetworkx like you mentioned before? it’s available as a standalone JS file - you can include that as a foreign dep in the usual way - people dropped links about how to do that earlier
this is not for money or anything, i don't have to make it for the pleasure of other people, it doesn't have a deadline. i don't like the idea of having to manage dependencies through html, as i also expressed before
i saw two other ways i think, one is the cljsjs thing and the other is foreign-libs i think, maybe the two are actually the same, i am not sure. My question was about these two, if I should try it.
well, there goes the "everyone is trying to help" assumption i think. not sure why are you so upset though, you seemed a nice, calm person irl 😞
foreign dependencies is how CLJSJS works, or if you do it yourself - it’s all the same stuff