Fork me on GitHub
#clojurescript
<
2018-12-06
>
sova-soars-the-sora00:12:24

(set! (.-addClass dom-node) "className") ?

jsa-aerial01:12:59

If a JS library uses ES6 features, would that cause any issues with Cljs? Put another way, everything else equal, would it be ok to use such a library?

mfikes01:12:10

I can’t think of any way that this would cause a problem for ClojureScript.

✔️ 4
ClashTheBunny03:12:42

Hey folks. What's the best way to get a cljs repl in a deps.edn project like advent-of-cljc? I tried the clj directions and got:

~/code/advent-of-cljc (master●)$ clj -m cljs.main
Exception in thread "main" java.io.FileNotFoundException: Could not locate cljs/main__init.class or cljs/main.clj on classpath.
	at clojure.lang.RT.load(RT.java:463)
	at clojure.lang.RT.load(RT.java:426)
	at clojure.core$load$fn__6548.invoke(core.clj:6046)
	at clojure.core$load.invokeStatic(core.clj:6045)
	at clojure.core$load.doInvoke(core.clj:6029)
	at clojure.lang.RestFn.invoke(RestFn.java:408)
	at clojure.core$load_one.invokeStatic(core.clj:5848)
	at clojure.core$load_one.invoke(core.clj:5843)
	at clojure.core$load_lib$fn__6493.invoke(core.clj:5888)
	at clojure.core$load_lib.invokeStatic(core.clj:5887)
	at clojure.core$load_lib.doInvoke(core.clj:5868)
	at clojure.lang.RestFn.applyTo(RestFn.java:142)
	at clojure.core$apply.invokeStatic(core.clj:659)
	at clojure.core$load_libs.invokeStatic(core.clj:5925)
	at clojure.core$load_libs.doInvoke(core.clj:5909)
	at clojure.lang.RestFn.applyTo(RestFn.java:137)
	at clojure.core$apply.invokeStatic(core.clj:659)
	at clojure.core$require.invokeStatic(core.clj:5947)
	at clojure.main$main_opt.invokeStatic(main.clj:317)
	at clojure.main$main_opt.invoke(main.clj:313)
	at clojure.main$main.invokeStatic(main.clj:424)
	at clojure.main$main.doInvoke(main.clj:387)
	at clojure.lang.RestFn.applyTo(RestFn.java:137)
	at clojure.lang.Var.applyTo(Var.java:702)
	at clojure.main.main(main.java:37)

dpsutton04:12:17

If you want to go that way I think you just need to ensure that a recent clojurescript is in your deps

ClashTheBunny04:12:05

So, do I move it from the :test :extra-deps section to the regular :deps section? org.clojure/clojurescript {:mvn/version "1.10.439"} is in the extra-deps section of test.

ClashTheBunny04:12:41

⬆️ worked!

quoll04:12:53

Self hosting ClojureScript drives me nuts. Make a tiny change in some unrelated place, and suddenly you can’t eval anything anymore

quoll04:12:12

A few weeks ago I could eval the expression: (fn [a b] (not= a b))

quoll04:12:39

But now? WARNING: Use of undeclared Var cljs.user/fn

quoll04:12:38

so I changed it to eval: (cljs.core/fn [a b] (not= a b))

quoll04:12:09

All that did was change it to: WARNING: Use of undeclared Var cljs.core/fn

quoll04:12:22

To make it worse, the code runs just fine in node.js

quoll04:12:03

It only broke in the system that includes this as a dependency

quoll04:12:33

I should explain. That’s a cut down explanation. It’s really eval-ing: (fn [f1 d f2] (not= f1 f2)) And the response is:

WARNING: Use of undeclared Var cljs.user/fn
WARNING: Use of undeclared Var cljs.user/?f1
WARNING: Use of undeclared Var cljs.user/?d
WARNING: Use of undeclared Var cljs.user/?f2
WARNING: Use of undeclared Var cljs.user/?f1
WARNING: Use of undeclared Var cljs.user/?f2

quoll05:12:21

This isn’t the first project that this has happened to me (though the other one was just something for fun. This time it’s for work). Everything appears to work, and then something apparently unrelated gets modified, and suddenly vars are “undeclared”. Like it runs out of space somewhere and starts losing data. Is anyone familiar with self hosting ClojureScript? Suggestions where I could track this down?

quoll05:12:04

I do have a fallback position, which is to take the function I’m wrapping (in this case, the not= function), and call it directly with only the arguments it needs. Given the way the incoming data works, that will be annoying, but I can do it. Using eval was supposed to save me significant effort 🙂

Rina10:12:48

I'm looking for ways to speed up the compilation I added :parallel-build true to compilation options It works fine when :optimizations :none But the're an error in the console Cannot read property 'prototype' of undefined when :optimizations :advanced

Rina10:12:42

And ideas why :parallel-build true causes errors?

thheller10:12:48

@rinam did you verify that you do not get that error when using :parallel-build false + :advanced? :parallel-build should not affect :advanced

Rina10:12:08

Yes, I did

thheller11:12:47

what are you using to compile? which cljs version?

Rina11:12:49

Why isn't :parallel-build true default if it speeds up compilation?

Rina11:12:36

@thheller I'm using version 1.9.660

thheller11:12:16

that is rather old. try upgrading. I think there were a couple issues related to :parallel-build in the past. 1.10.439 is the latest release

Rina11:12:02

Thanks, I'll try it

Rina11:12:51

Is there anything that I should be aware of when upgrading to this version? Any deprecated functions?

thheller11:12:47

I don't think so. may also need to bump your build tool though.

Rina11:12:00

I'll try

Rina11:12:20

Do you have any other idea for speeding up compilation?

john11:12:31

There was that map-entry change, from vectors to legit MapEntry, but unlikely you'll hit it

thheller11:12:33

yeah .. use shadow-cljs 😉

🔥 16
john11:12:12

The newer cljs's cut compilation times in half, I thought

Rina11:12:22

Wow! It will make a major difference to us, since we have a huge project in clojure

john11:12:24

Yeah, david nolen and mike fikes did some crazy good optimization work the last release cycle. Def try it.

scknkkrer11:12:25

Have someone try to use react-toastify ? https://github.com/fkhadra/react-toastify

scknkkrer11:12:06

I couldn’t get it done.

scknkkrer11:12:31

I get this error;

Invariant Violation: Unable to find node on an unmounted component.

scknkkrer11:12:43

But the component worked well.

scknkkrer11:12:53

Everything feels alright.

scknkkrer11:12:53

But the error disturbing me.

dnolen15:12:31

@dustingetz @borkdude goog.global is probably the best way

dnolen15:12:20

@rinam there were definitely compiler perf enhancements in the last release, but how much it will affect compilation time really depends on your project, many people report improvements but they were quite modest. Also twiddling JVM memory settings is a good idea in case you're not giving the process enough memory, a common problem

Bravi15:12:32

hi everyone. is it possible to convert duration that is in milliseconds, to time?

Bravi15:12:43

or should I defer to js methods?

Bravi15:12:49

time, as in like how much time was spent basically

cjsauer15:12:47

@bravilogy what units are you trying to convert to specifically? Milliseconds to seconds? To hours?

cjsauer15:12:07

If you're looking for a more natural language output (e.g. 6 hours, 7 minutes, 32 seconds), then you can use a function that exists within the Google Closure library: https://google.github.io/closure-library/api/goog.date.duration.html

Bravi15:12:57

basically it’s a little game I’m working on and players are given maximum of 3 hours to do something and whoever does it quickest, is the winner. so the most that should be shown is an hour. i.e. 1hr 2mins and 37seconds is a valid output

Bravi15:12:05

or just 12seconds is a valid output too

cjsauer15:12:19

I see. Check the link above. I think that's exactly what you're after.

Bravi15:12:41

nice one, looking into it now 🙂 thank you!

👍 4
cjsauer15:12:21

GCL is already included in all ClojureScript projects as well, so you should be able to just require the function: https://github.com/clojure/clojurescript/wiki/Google-Closure-Library#requiring-a-function

Bravi15:12:33

if (ms < goog.date.duration.MINUTE_MS_) {
    /**
     * @desc Duration time of zero minutes.
     */
    var MSG_ZERO_MINUTES = goog.getMsg('0 minutes');
    return MSG_ZERO_MINUTES;
  }
why do they have this 😄

Bravi15:12:42

it will return 0 minutes in most cases

cjsauer15:12:25

@bravilogy I suppose you could always check yourself whether the time is less than one minute, and if so, just display (/ ms 1000) seconds

cjsauer15:12:56

Otherwise you can fall back to the duration function

Bravi15:12:01

yeah, probably that’s what I’ll do. thank you so much for your help

cjsauer15:12:22

No problem

borkdude16:12:52

@dnolen cool. it seems goog.global is used in getObjectByName, so you can do:

(goog.getObjectByName (munge "cljs.core.some?"))

❤️ 4
hoopes16:12:59

how would i go about creating mock hiccup elements in my karma tests?

(ns ui.utils-test             
  (:require [cljs.test :refer [deftest is testing]]    
            [hiccup.core :as h]    
            [ui.utils :as utils]))
The required namespace "hiccup.core" is not available, it was required by "ui/utils_test.cljs".
"hiccup/core.clj" was found on the classpath. Should this be a .cljs file?
I'm in shadow-cljs, not sure how to do lein tree type thing to grep for hiccup (or whatever library is actually creating my elements...)

thheller17:12:57

@hoopes hiccup is a clojure-only library. it does not support CLJS. you'll need some other library for that.

richiardiandrea17:12:00

@thheller question, what do you thing of having something like {:install-cmd ["npm" "install" "--no-audit" "--no-save" "--no-package-lock" :packages]} the default npm command? it gets rid of a lot of noise and avoids polluting the repo

thheller17:12:22

at least I want safe and package lock?

thheller17:12:00

if it was my choice this feature would not exist at all

richiardiandrea17:12:00

isn't this for transitive deps? do you check those changes in the parent lib?

richiardiandrea17:12:00

I mean when I call yarn shadow in the client lib I want the deps pulled in but not in package.json of the client lib

richiardiandrea17:12:05

unless I am missing something

thheller17:12:57

not sure I understand what you mean

richiardiandrea17:12:19

so I have a lib A which uses lib B containing a deps.cljs

richiardiandrea17:12:41

when I do yarn shadow-cljs with defaults, it modifies the package.json of lib A

richiardiandrea17:12:34

I think I do not want that

richiardiandrea17:12:52

but I am curious to understand why

shaun-mahood18:12:29

There is also https://github.com/teropa/hiccups if that doesn't work for you

hoopes18:12:37

:thumbsup: thanks!

genekim18:12:55

Holy smokes — I’m embarrassed that I’ve spent 5+ hours on this problem, but I’ve finally narrowed it down to a surprising conclusion… Can anyone help me figure out how to solve this problem? I was using https://github.com/metosin/komponentit/blob/master/src/cljs/komponentit/clipboard.cljs to copy text into the clipboard. It works terrific… but only when Google Closure compiler optimization is turned off. When optimization is turned on, the clipboard always remains unchanged. [insert lots of investigation] Mysteriously, the execCommand("copy") always returns false and fails to copy text to the clipboard when Closure advanced optimization is turned on. I even resorted to writing it purely in JavaScript, as per https://hackernoon.com/copying-text-to-clipboard-with-javascript-df4d4988697f, and using js interop to call that function. And even when the execCommand in pure JavaScript, when called from a CLJS program that has been Closure optimized, it fails. Is there something I need to call that would enable execCommand("copy") to work in an CLJS/Closure optimized program? Many thanks in advance for helping me regain my sanity!!!! 🙂

genekim18:12:03

// from: 
const copyToClipboard = str => {
  const el = document.createElement('textarea');  // Create a <textarea> element
  el.value = str;                                 // Set its value to the string that you want copied
  el.setAttribute('readonly', '');                // Make it readonly to be tamper-proof
  el.style.position = 'absolute';                 
  el.style.left = '-9999px';                      // Move outside the screen to make it invisible
  document.body.appendChild(el);                  // Append the <textarea> element to the HTML document
  const selected =            
    document.getSelection().rangeCount > 0        // Check if there is any content selected previously
      ? document.getSelection().getRangeAt(0)     // Store selection if found
      : false;                                    // Mark as false to know no selection existed before
  el.select();                                    // Select the <textarea> content
  const retval = document.execCommand('copy');    // Copy - only works as a result of a user action (e.g. click events)
      // ^^^ this works and returns true when CLJS is not Closure advanced optimized
      //     it returns false when Closure advanced optimization is turned on
  document.body.removeChild(el);                  // Remove the <textarea> element
  if (selected) {                                 // If a selection existed before copying
    document.getSelection().removeAllRanges();    // Unselect everything on the HTML document
    document.getSelection().addRange(selected);   // Restore the original selection
  }
  console.log(" copyToClipboard : ", str);
  console.log(" copyToClipboard returned: ", retval);
};
console.log("loaded copyToClipboard widget!")

thheller18:12:35

@genekim works fine for me. does your :advanced build maybe change something else that changes the semantics of the call? I think copy is only allowed as the result of a user event. so it can't be done via setTimeout or so IIRC

XORshift18:12:03

Howdy! I am having some trouble determining how to lein deploy/release my Serveless ClojureScript project to S3. What I have working => I have already configured my project with wagon plugin and releases/snapshots repos. When I lein deploy my distribution is pushed to the correct location in S3. The problem is that the distribution is a JAR file. Normally I would create a distribution by running sls package which would create a zip to deploy to AWS along with CloudFormation stack files. Serverless does log the lein command to the console, it looks like this:

lein update-in :cljs-lambda assoc :functions '[... function maps here...]' -- cljs-lambda build :output /output/path/.serverless/project-distro.zip :quiet
I would like to run this command as part of my deploy and as part of my release so I could at least push the zip file to my repositories in S3. Is this possible?

genekim18:12:05

@thheller Holy smokes. Thank you for the data point! On the one hand, I’m delighted to know it works in certain conditions. On the other hand, I’m like 😱😱😱. 🙂 [Now scratching head, trying to figure out what could be different… It’s a re-frame app, but surely that can’t be it?]

thheller18:12:04

not a clue. I tested with pure DOM interop (no react) and that worked fine.

XORshift19:12:15

Is it acceptable to cross post questions to other channels? For example the same question to Beginners and Clojure?

genekim16:12:00

I’ve done it on occasion, in my desperation. :) FWIW, no one complained (or noticed. :). Good luck!

genekim19:12:52

Moving to #re-frame

genekim19:12:45

@thheller I’m sure you’re right! It’s an asynchronous event, and I’m sure it’s no longer an user-event. THANK YOU!!!!!

genekim19:12:12

OMG. @thheller It worked! Wow! THANK YOU!!!! You’re so fantastic! (And you were fabulous in the defn and REPL podcasts. :)

😎 4
🙂 4
victorb20:12:07

ugh, I've been fighting to have something basic working that uses clojurescript + figwheel + nrepl (for vim-fireplace integration) + webpack for external npm dependencies, but I can't seem to get both npm deps + nrepl to work together... Anyone knows any example with these used together?

dnolen21:12:06

@victorbjelkholm429 a good question to ask yourself - do you need :npm-deps

dnolen21:12:13

the answer is almost 90% ... no

dnolen21:12:29

if you're just talking about the webpack integration

dnolen21:12:32

what's the problem?

dnolen21:12:41

I don't see how nrepl has anything to do with that

dnolen21:12:13

(sorry I think maybe you were saying that re: webpack above, didn't read closely enough)

dnolen21:12:33

build stuff, and REPL integration are really quite independent

victorb21:12:43

let me publish an example and pinpoint exactly where the issue is, it'll be easier

victorb21:12:22

ok, I don't really need figwheel in the end, as long as rebuilding + remote repl can be setup in some other way. However, I cannot find any documentation on clojurescript on how that would be done. I made a greenfield project where the basics are setup but still missing some rebuilding + remote repl setup with clojure-tools. https://github.com/victorb/cljs-peer-star-app

sova-soars-the-sora22:12:22

so uh is jwt something i should look into instead of sessions?

richiardiandrea23:12:35

question, does cljs.spec.alpha/check-asserts influence the instrument call in any way?