Fork me on GitHub
#clojurescript
<
2018-05-12
>
benzap04:05:43

I'm curious on whether ES6 Modules will simplify how clojurescript will handle modules in the future. It seems to have it's own system of handling CommonJS modules and similar modules

dominicm09:05:13

What is the conventional way to export clojurescript code as a node.js module? That works with require()

Bravi12:05:11

is there a way to get the current route using secretary to set an active class on a link?

Bravi12:05:51

actually never mind, came up with a different way to do this

richiardiandrea14:05:17

@dominicm I do not think core provides something more than ^:export, I might be wrong though

richiardiandrea14:05:58

So you can expose symbols that become JS vars, what is your use case?

dominicm14:05:34

@richiardiandrea I found a blog post saying I needed to write some "shim" javascript to re-flatten things out. I've ended up with:

var clj_refactor = require('./compiled.js')

module.exports = clj_refactor.clj_refactor.main._main

richiardiandrea14:05:11

@dominicm yes that is what I do in my lamdbas as well. In comparison, shadow-cljs has more options regarding JS consumption, one explicitly for node library.

dominicm14:05:46

Maybe I shall give that a shot later then 🙂 thanks

MegaMatt16:05:03

I'm using a clojurescript library that i need to modify. Is there a good way of doing this? like can i fork the repo and point the project.clj dependency somehow at a local folder while i fix the issues?

justinlee17:05:48

With shadow-cljs you can shadow single files locally that will override anything from a jar. https://shadow-cljs.github.io/docs/UsersGuide.html#_hacking

levitanong16:05:56

hi all, is default-destructuring supported on namespaced keywords?

(let [{:keys [foo/bar] :or {foo/bar 2}} something])

mfikes17:05:53

@levitanong (let [{:keys [foo/bar] :or {bar 2}} something])

mfikes17:05:34

Or, if you prefer the symmetry: (let [{:foo/keys [bar] :or {bar 2}} something])

levitanong18:05:47

@mfikes whoa, i didn’t know the latter was even possible. The former didn’t seem to work for me.

mfikes18:05:09

@levitanong So, for example (let [{:keys [foo/bar] :or {bar 2}} {:foo/bar 42}] bar) doesn't evaluate to 42 for you?

mfikes18:05:59

(let [{:keys [foo/bar] :or {bar 2}} {}] bar) -> 2

levitanong18:05:55

i just realized something… if the object being destructured is {:foo/bar nil}, then it shouldn’t be 2, because the value was explicitly stated to be nil

levitanong18:05:19

@mfikes so if the latter is a thing, then does that mean that, given:

(def thing {:foo/bar 2 :baz/rutten 3})

(let [{:foo/keys [bar] :baz/keys [rutten]} thing])
;; bar = 2
;; rutten = 3

mfikes18:05:41

Sure; (let [{:foo/keys [bar] :baz/keys [rutten]} thing] [bar rutten]) -> [2 3]

levitanong18:05:10

holy moly, that is so cool!

levitanong18:05:24

anyway, thanks for your help @mfikes!

justinlee19:05:34

are there any debugging / logging libraries out there that deal with javascript objects and clojurescript datastructures with equal ease?

justinlee19:05:01

i’m so tired of getting [Object object] or whatever as output when i’m confused about the type of the variables i’m trying to debug

joelsanchez19:05:10

js/console.log with cljs-devtools has no problems with either

justinlee19:05:02

right that’s a good point. i sure would like a pretty printer though. it is much easier than drilling down

justinlee19:05:46

the other thing with that approach is that it only works if you pass the object unchanged to console.log so when used with spy macros and other types of logging conveniences (like using color output in the console) it is hard to get that to work right

darwin19:05:05

to see [Object object] someone must be calling toString on your javascript objects, probably calling str on them

darwin19:05:20

I think if your logging library was written properly it would serialise javascript objects via pr-str which goes through pr-writer machinery which tries to drill into #js objects and print them as cljs maps, here is a proof: https://github.com/clojure/clojurescript/blob/78753d376d5bfe9afd1dbb98eea15fd5bd312255/src/main/cljs/cljs/core.cljs#L9936-L9943

justinlee20:05:37

yes that’s exactly what’s happening because I’m trying to get fully expanded logging in certain circumstances. sometimes with deeply nested structures, it is simply nicer to have it expanded out so I don’t have to drill down with the mouse

justinlee20:05:04

i’ve also been trying to experiment with the color output features of chrome, because it can be really handy to selectively print stuff in red so that i can find it quickly. but to do that, you have to get to a string representation

zalky20:05:07

Hi all. I'm trying to interop with a JS lib, and have had to write a really basic externs file and an accompanying foreign lib:

var SlateAutoReplace = {
  "AutoReplace": function() {}
};
When I require the lib and try to use the loaded JS, the AutoReplace fn exists as a default attribute in the SlateAutoReplace module object. In order to call the fn I have to do:
(.default js/SlateAutoReplace args...)
But the following fails:
(js/SlateAutoReplace.AutoReplace args...)

zalky20:05:03

I'm guessing this is because AutoReplace was export default, but I've never seen this form of interop and I'm wondering if I've missed a step.