This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-11-02
Channels
- # admin-announcements (1)
- # aws-lambda (9)
- # beginners (161)
- # boot (1)
- # cider (3)
- # cljsrn (36)
- # clojure (245)
- # clojure-austin (2)
- # clojure-denmark (3)
- # clojure-dev (11)
- # clojure-greece (6)
- # clojure-italy (25)
- # clojure-russia (5)
- # clojure-serbia (1)
- # clojure-spec (76)
- # clojure-uk (78)
- # clojurescript (168)
- # clojurex (4)
- # community-development (7)
- # core-async (11)
- # core-logic (5)
- # css (6)
- # cursive (8)
- # data-science (6)
- # datomic (5)
- # devops (4)
- # duct (17)
- # emacs (1)
- # figwheel (8)
- # fulcro (51)
- # hoplon (4)
- # instaparse (3)
- # kekkonen (6)
- # klipse (3)
- # lein-figwheel (9)
- # luminus (2)
- # lumo (3)
- # midje (4)
- # off-topic (11)
- # om (4)
- # onyx (62)
- # other-languages (60)
- # re-frame (21)
- # reagent (63)
- # rum (1)
- # shadow-cljs (22)
- # spacemacs (22)
- # specter (23)
- # test-check (2)
- # vim (2)
- # yada (6)
Hi, how to make goog.debug.ErrorReporter
work in ClojureScript? I added this to my code and it did send a POST
request. But when the page get errors in js
it did not send POST
requests.
(defn install-error-reporter
[]
(let [reporter (.install goog.debug.ErrorReporter error-reporter-url)]
(.sendErrorReport reporter "safdsf" "safsdfsaf" 16)))
quick question on using nodejs with clojure … how do I obtain the value of an env variable?
goog.object makes working with it pretty easy https://google.github.io/closure-library/api/goog.object.html
@raymcdermott try this: https://gist.github.com/metametadata/b67a3e7f722589e04b021d60510be504
Javascript question. I'm looking for the equivalent of (doto x js/console.log)
in pure JavaScript. Is (function(v){console.log(v);return v;})(x)
the best I can do even in modern JS?
(especially if x
is actually a more complicated expression)
@metametadata yay! thanks that’s perfect
@pesterhazy In somewhat modern JS: (v=>(console.log(v),v))(x)
@p-himik aha, the comma operator
I never knew there was such a thing
thanks!
Is there a way to guarantee a namespace is loaded before anything else? Preload doesn't seem to do it. Context: cljs is loading the process.env shim after some node_modules that needs it, causing 'process is not defined' errors. These node libs don't explicitly require
it, which I think confused the dependency sorter.
Now I have to define it in the html :thinking_face:
@poernahi I've created an issue for that: https://dev.clojure.org/jira/browse/CLJS-2393
As of the solution, I didn't find any except for delaying the inclusion of code that requires process.env
.
hmm.. interesting
so, if I manually add process.env on top of the preload list, it should work? time to test...
Hm, for some reason this solution did not occur to me at all. 🙂 Let us know what you'll find.
yup, it worked!
thanks for that link
wow re-frame.trace is awesome
Can anyone explain what this means (from the CLJSJS website): “You can now use your newly added library by accessing it through the global Javascript namespace, e.g. js/React. Please check the project’s documentation to find out what global the library uses.” and further to that, does anyone have any example code they can share of using recharts via CLJSJS in clojurescript, please?
I am very__ new to clojurescript, but I have a solid JS grounding, so the examples on the recharts website for JS 1.7 make sense - it’s just that now I need to figure out how to do the same things in ClojureScript…
@maleghast js
is a pseuso-namespace (or a "magical" one), that essentially provides access to the global JavaScript scope. So, for example, js/console
refers to the global console
object.
@mfikes - Ah ok… So once I’ve added the package for recharts to my build.boot and required it in the cljs namespace where I want to use it, I need to figure out the right global object for recharts..?
so in your case, I think it would be js/Recharts
@maleghast Essentially, yes. Oftentimes you use js/
interop to access a library via a global that it has established
here's an example project https://github.com/compassus/omify/blob/master/src/devcards/omify/devcards/core.cljs
@maleghast What error? By the way, https://clojurescript.org/guides/quick-start#dependencies is probably worth a read if you haven't done so already
@mfikes - I think I’ve sorted it; I thought that my environment would grab the dependency all by itself but apparently not… I stopped my app and re-started it and I am getting messages in my console about the relevant dependencies being retrieved now.
I am feeling the n00b thing, pretty hard, but I have to say that I am finding cljs easier than the last time I looked at it…
has anyone found that their cljs builds, using lein-cljsbuild
do not exit on WARNINGS
? for instance, a warning such as Wrong number of args passed to ...
shows up as a WARNING, but surely the compiler should exit at a warning like that? that is broken code
@biscuitpants There is definitely a philosophical stance taken that warnings are not fatal. Perhaps there is a good reason arity problems are deemed warnings in ClojureScript (while not so in Clojure)—perhaps related to the way the JavaScript host behaves.
that is understandable, but is there a way to configure it to exit on these warnings? i’ve tried using the warning handlers hook, but i would need to filter out a lot of false positive warnings, which is also a brittle way to solve this problem
@biscuitpants Yes. You can take a specific warning and essentially cause it to be fatal. In other words you could specifically make arity warnings fatal.
via the warning handlers, like i described above?
ah, okay. hopefully there is more concrete support for this in the future. maybe a way to set the level of warning on which the compiler exits?
@biscuitpants Here is an example I use when building Planck. I chose to white-list the ones I want to be non-fatal, but you could employ any logic you'd like: https://github.com/mfikes/planck/blob/master/planck-cljs/script/build.clj#L26-L27
thank you! that is a great start
haha so we are doing exactly what you are doing, except using regex’s at the moment. using keywords would be much better, so thank you!
Oh, right. Yes, using concrete keywords instead of regex's on the strings is mas bueno
very much so. thank you, i really appreciate the help @mfikes
FWIW: My recollection of the philosophy / stance (from a discussion with David on IRC a few years back) goes along the lines of: If it is at all possible for the analyzer to actually analyze the code and produce a well-formed AST, then it will do so, while at most emitting warnings. The analysis step will only fail if it simply cannot analyze what has been read. This results in a bit of looseness that caters to the Lispy dynamic nature of things at the REPL, thus facilitating, for example, seeing an arity warning, and then either changing the call, or changing the target function. In other words, it is fairly conservative, so long as it can generate an AST that the compiler can use to generate legit code, letting you as the developer decide what to actually do when warnings are emitted. This also makes it possible to see all of the analysis warnings in a given compiled namespace without it blowing up prematurely.
yeah, i understand that there needs to be some catering done, because of Lisp. it is nice to see all of the warnings at once, without having each warning blow up the process
Can any Garden users in here help me create padding settings? I’m currently defining padding using a vector like [(px 1) (px 2)]
… but my output styles are comma-separated values like padding: 1px, 2px
which Chrome isn’t recognizing as valid CSS
any help here would be greatly appreciated bc I recently ported most of our existing styling over to Garden and now we’re suffering from styling regressions, which is unfortunate… I cannot seem to find anywhere in the docs that point to the proper way of handling this
@wpcarro It might not be the solution you're looking for but what I usually do if I need to define multiple padding values using shorthand is just use a string:
:padding "0 0 10px 0"
and if I need some variable in there I'd do this:
:padding (str "0 0 " (px my-variable) " 0")
Not very elegant but like you pointed out garden handles vector input a bit differently than say JSS, where using an array is valid.@roosta hmm I had a lot of code like that originally, but it breaks down for thing like box-shadow
shorthand… imagine you need to encode x
y
blur
and color
… how can you stringify garden colors?
and when you call (str ...)
on these you get outputs like
(str (color/hsl 100 100 100))
"garden.color.CSSColor@f9ec246b"
hmm, I haven't really used the color functions in garden a whole lot. I just asssumed they retuned a string but clearly not.
Does clojure promise not exist in clojurescript?
Oh damn, that explains things. Kept getting undefined
Thanks
maybe Garden should expose a shorthand function that can automate a lot of this. I think this only breaks down in shorthand definitions anyways, so maybe that’s a clean fix
Hey, I am working on packaging a javascript library for use in clojurescript. I want it to work as if I had provided the :npm-deps
requirement but while using the :foreign-libs
(e.g. I can use (:require [my.components :as components])
Is this possible?
Note: My javascript library is not globally loaded, so I can not use the :global-exports
key
@wpcarro sounds like a good idea, but as far as a solution to your predicament, i don't rightly know. your guess is as good as mine. A macro could maybe simplify the shorthand syntax, by wrapping render-css or something
@kasuko https://clojurescript.org/guides/javascript-modules#javascript-modules this example is es6, but should be easy to update for commonjs if you're using that.
I did run into https://github.com/google/closure-compiler/issues/2634 when I tried to use it though (for commonjs)
It seems that you're using React, if you've got JSX in the mix, you should also see https://clojurescript.org/guides/javascript-modules#babel-transforms
@roosta take a look at this if you’re interested! https://github.com/noprompt/garden/issues/15
@wpcarro that seems but address at least the comma separated shorthand issue. nopromp mentions using [[]] for space separated, did you try that for the padding?
@roosta yea it works… it’s great. I’m going to submit a PR later this week to augment the docs because it isn’t very clear
@dominicm Thanks, that got me a little further, however it’s actually a UMD module and when I try to load it in it fails to load the the ‘react’ and ‘react-dom’ modules. I do have :requires ["react" "react-dom"]
in my foreign-libs
Maybe a better way to get this to work would be to force my UMD module to load itself into the global namespace. This works fine if I am running it without :optomizations
but as soon as I try to compile it with the :optimizations
it no longer loads in the global namespace
speaking of UMD modules.. Can anyone help me understand CLJS-2327? cljs now prefers browser
instead of module
from package.json. In the lib I'm using (react-apollo), browser points to react-apollo.browser.umd.js
while module points to index.js
which uses ES6 exports/import. CLJS was able to consume index.js, but breaks on the umd because the umd is trying to pull some global names like window.React
which is exported as some$long$path$React
. I want to file a bug, but I'm not sure if the problem is CLJS, rollup (the packager that writes umd) or react-apollo (the one who writes package.json). I don't know enough about modern js packaging...
@thheller I wish, it’s my companies private component library. However I figured out the issue, since I control both the JS and the CLJS I was trying to sneak the CLJS wrapper in the same namespace as the JS library.
So under advanced compilation the namespace of the wrapper was clobbering the top level var that the library was in
Could you please help me? What if I want each re-frame page or component to be in separate files but in same namespace?
Is it possible? The component is function with its own name, and if it needs its own namespace, the component usage looks like this:
components.my_component.my_component
, and that's not great
that's possible in clj, I think it's possible in cljs (though trickier), but it's usually nota good idea
this is what the :as arg to require is for - to get shorter aliases to other namespaces
that's the normal way to do things, using other namespaces and not requiring them is a very bad idea
the require block should help someone who reads your code to know what other code it depends on, and where to go to find it
But I want them to be used like components.foo
and components.bar
, and its possible only if the components are defined in same file
that's not how clojurescript or clojure is typically done. It's possible but it will be weird, and there's problems with working that way.
it's a relatively opinionated language
So how is it typically done? Reframe Boilerplate puts all the components in one single file, and that's not how you make your app scalable
@melvoloskov what about letting them sit in their current location and then introduce a new namespace having just references to those long component vars?
e.g. in components namespace do (def my-component components.my-component/my-component)
one of the best things about clojure is making scope and bindings explicit and non magical, anything that works around this is undermining one of the language's best features IMHO
you can go fancy and use a macro to generate that aux namespace defs by walking defined stuff in source namespaces
it would look like this: https://github.com/binaryage/cljs-devtools/blob/master/src/lib/devtools/formatters/markup.clj usage here: https://github.com/binaryage/cljs-devtools/blob/master/src/lib/devtools/formatters/markup.cljs#L438-L451
By the way, re-frame uses case
to define a page to show, but I just want to replace it with something that takes page's name and looks it up in pages
namespace, and if it's found, it just returns that page, and if it's not, it returns the predefined page, for example 404 page
Because if you want to add a page, you need to do the following:
1. Define page component
2. Define it's route
3. Define page's name into that case
why not to omit third step to make the code more dry?
be careful with keyword, it will happily generate nonsense
+user=> (keyword " lmn p")
: lmn p
if the data is coming from a string at runtime, it often makes sense to use strings instead of keywords in the first place (cljs will happily use strings as keys in hash maps etc.)
keywords aren't functions
well, you can call them, but they don't refer to functions you have defined
yeah, keywords are not for that at all
you can use resolve / symbol to find a function by name, but it's usually a sign you are making a mess if you resort to such things
it's needed by tools like lein though
keywords are a data type that stands for itself and has a readable name
that's what they are for
like an enum
keywords are often used for maps but clojure will happily hash anything and use it as a key
+user=> ((resolve (symbol "+")) 2 2)
4
- this works, but is a good way to end up with a messit was an arbitrary choice of function that everyone knows what it does and knows the answer is correct
tools like lein use this to start your clj project
you're catching on 😄
we do have things for dependency injection - eg. defmethod and defprotocol to define things that can be extended by other code
and you can get a new behavior by defining a new extension of the method or protocol
but usually pure functions plus immutable datatypes is the path to glory with clojure
not quite - for example you can extend a protocol you don't own to a class you don't own
it's runtime extension, using some of the same approaches OOP uses
but once again, pure functions and immutable data are usually the right choice, and it's best to stick with those until you realize you need those other structures
goog.object/get <-- does using this get around all the cljs optimizations renaming issues ?
you’re referring to try to grab a property from an object that you know will be there at runtime?
seems like goog.object/get should work. I’ve used aget
before, but i’m not sure it’s the “right” way to do it
ok, using aget
is not the right way
https://www.html5rocks.com/en/tutorials/getusermedia/intro/ <-- is there a cljslibrary that wraps getUserMedia ?
I trying to use a typescript library with :npm-deps
and I'm using https://github.com/binaryage/cljs-oops to access functions and stuff with oget
and ocall
, but this doesn't work with advanced optimizations. I can print the object that serves as the "namespace" of the library at runtime, but the call (ocall PrismicJS :api url)
returns an api object with optimizations :none
and returns null
with :advanced
. Where should I start looking here?
And, in general, do I still need to generate externs when I use cljs-oops for all my calls to libs in :npm-deps
?
"No! Use oops only for interop with external code which is not part of your :advanced build. That means for all code where you would normally need to write externs."
I'm not familiar with :npm-deps, but reading this https://clojurescript.org/news/2017-07-12-clojurescript-is-not-an-island-integrating-node-modules for you
"Gluing it all together is the :npm-deps compiler flag. In it, we tell the compiler which dependencies it should be aware of. ClojureScript will take care of installing those dependencies and running them through the Closure Compiler conversion pipeline, including optimizations which we describe in more detail below."