Fork me on GitHub
#clojurescript
<
2021-05-12
>
zackteo02:05:11

Does anyone know where is the github repo for the re-com site - https://re-com.day8.com.au/#/layout? I saw some unbalanced brackets in the doc

zackteo03:05:29

Whoops. Thank you! I overlooked the fact that the site was in the same repo

p-himik08:05:26

Also, if you click on any specific component, the top of the page will have two links - one for the component source code, and the other for the page source code.

👍 2
hindol08:05:50

Is there an equivalent of ClojureDocs for ClojureScript?

niwinz08:05:34

I don't know if it is equivalent, but I'm always using https://cljs.github.io/api/

👍 4
🙏 4
hindol09:05:18

Yes, this one I know of. The main strength of ClojureDocs (to me) is the community provided recipes. I find them super useful. So I was just wondering if there is a similar site for CLJS.

hindol09:05:57

I am comfortable with Clojure. Which book would you suggest for ClojureScript?

solf09:05:56

Most of clojuredocs is valable for clojurescript too though

solf09:05:25

I wish clojuredocs integration in cider would work for clojurescript

hindol09:05:41

Nice. Did not know about the ClojureDocs integration in CIDER. Just tried it out. Strangely, it does not have documentation for loop. Is it using an older snapshot?

solf09:05:25

Hmm don’t know, it should work

or11:05:53

Hola. I'm using shadow-cljs and the generated source-map appears to map all output line columns to 1, so the mapping doesn't work. For instance, the output of decode-source-map:

{:version 3,
 :sources ["zprint/finish.cljc"],
 :mappings {:537 ["1 => zprint/finish.cljc 336:1 p__41998"
                  "1 => zprint/finish.cljc 336:1 cljs.core.nth"
                  "1 => zprint/finish.cljc 336:1 vec__42000"
                  "1 => zprint/finish.cljc 336:1 vec__42000"
                  "1 => zprint/finish.cljc 336:1 vec__42000"
                  "1 => zprint/finish.cljc 340:19 focus-begin"],
            :238 [""],
            :419 ["1 => zprint/finish.cljc 285:1 s"
                  "1 => zprint/finish.cljc 290:3 s"
                  "1 => zprint/finish.cljc 290:9 nl-split"
                  "1 => zprint/finish.cljc 290:18 nl-split"
                  "1 => zprint/finish.cljc 290:18 nl-split"
                  "1 => zprint/finish.cljc 290:19 clojure.string.split"
                  "1 => zprint/finish.cljc 290:40 clojure.string.split"
                  "1 => zprint/finish.cljc 290:40 clojure.string.split"
                  "1 => zprint/finish.cljc 290:45 s"],
...

or11:05:30

Anyone got an idea what the problem might be? In the browser I can't jump to the right line, and I suspect it is due to this. I've compared the source-map with one generated by boot, there it is fine. The compiler option :source-map true is the same for both.

p-himik11:05:53

Given that boot works, this might be worth asking in #shadow-cljs

or11:05:43

Ah, thanks. I didn't see there was a more specific channel. 🙂

thheller11:05:45

There are clearly several entries that aren't column 1? so "all output" doesn't seem accurate?

thheller11:05:44

are you looking at the wrong "column"? the one that references the sources index? that'll always be 1 since there is only one file?

or11:05:20

Those are the line numbers of the output file, if I understand it correctly. And then inside those value lists you see all of them start with "1 => ...", those should be the columns.

or11:05:33

I'll generate a working one. And I think I just found a shadow-cljs version where it worked. Perhaps I can manually bisect my way to where it changed.

thheller11:05:51

feel free to set up a reproducible repo. As far as I can tell source maps work perfectly fine

or11:05:43

Yeah, I can't reproduce what I think I just saw. Same behaviour now with the older shadow-cljs version. I'll dig a bit deeper and post again in the other channel.

flowthing14:05:14

Any thoughts on why this:

λ clj -Srepro -Sdeps '{:deps {org.clojure/clojurescript {:mvn/version "RELEASE"}}}' -M -m cljs.main --repl
Downloading: org/clojure/clojurescript/maven-metadata.xml from central
ClojureScript 1.10.844
cljs.user=> (ns foo.bar)
Either hangs indefinitely or throws this:
Execution error (InternalError) at (<cljs repl>:1).
too much recursion

or15:05:10

I can't reproduce this either.

flowthing15:05:52

All right, thanks to both of you for trying. This is getting even more bizarre.

flowthing15:05:20

I'm on Zulu JDK 16, FWIW.

flowthing15:05:43

I can reproduce it with OpenJDK 11, too, though. 😕

p-himik15:05:14

When it throws, does *e in the REPL produce anything?

flowthing15:05:46

Unfortunately.

flowthing16:05:12

I can also reproduce it on a different machine that's running a different OS, Java version, and even CPU architecture. Really weird.

flowthing17:05:24

OK, this is browser-related, maybe a browser extension messing with something. I can reproduce the issue with Firefox, but not with Safari.

flowthing17:05:57

...or not. It sometimes hangs with Safari, too. Oh well.

p-himik17:05:26

When it hangs, you should be able to pause JS execution and see the current stack trace.

p-himik17:05:35

Via the browser's DevTools.

flowthing17:05:45

Oh, yes, good tip, will try that. :thumbsup::skin-tone-2: ...except my browser crashed when I tried doing that. :P

p-himik17:05:34

Time to try all the browsers. :)

flowthing17:05:43

Heh, I guess so. 🙂

flowthing09:05:10

FWIW, I managed to come up with a minimal repro including a stack trace (reproducible with multiple browsers): https://github.com/eerohele/cljs-repl-blow-stack

p-himik10:05:11

I can reproduce it now as well, but only when the initial page was left there an the REPL session has been recreated. It seems that the problem is due to clojure.browser.repl/bootstrap being called multiple times. And goog.require ends up calling itself.

flowthing10:05:59

Great to hear someone else was able to reproduce it as well. Thanks for trying it out! I also filed an http://ask.clojure.org question about this issue, in case you feel like weighing in there: https://ask.clojure.org/index.php/10602/evaluating-an-ns-form-clojurescript-repl-throws-rangeerror

dpsutton15:05:43

weird. cannot reproduce

il-tmfv15:05:52

Hi I’m on 1.10.844 and I have an issue with .cookies.set Looks like it is complied from https://github.com/google/closure-library/blob/ff84fa63944b428da36006ec940b3b349a8d66d3/closure/goog/net/cookies.js#L167 to

hba.set = function(n, t, h) {
    var e = !1;
    if ("object" == typeof h) {
        var l = h.Lh;
        e = h.Mh || !1;
        var r = h.domain || void 0
          , b = h.path || void 0
          , u = h.Lg
    }
    if (/[;=\s]/.test(n))
        throw Error('Invalid cookie name "' + n + '"');
    if (/[;\r\n]/.test(t))
        throw Error('Invalid cookie value "' + t + '"');
    void 0 === u && (u = -1),
    this.Oc.cookie = n + "=" + t + (r ? ";domain=" + r : "") + (b ? ";path=" + b : "") + (0 > u ? "" : 0 == u ? ";expires=" + new Date(1970,1,1).toUTCString() : ";expires=" + new Date(Date.now() + 1e3 * u).toUTCString()) + (e ? ";secure" : "") + (null != l ? ";samesite=" + l : "")
}
As you can see some params are renamed (see argument h) like h.Lh Is it expected?

dpsutton15:05:14

it is expected. is this causing issues for you?

il-tmfv15:05:05

Yes, basically I cannot pass maxAge param b/c it becomes something like Lh

il-tmfv15:05:42

BTW, path and domain are left untouched

dpsutton15:05:59

are you calling this from javascript or clojurescript?

dpsutton16:05:34

oh i'm following you now. It's not the arguments to the function but the properties on an options object that are being renamed

il-tmfv16:05:54

from cljs, a pass it as #js {:maxAge 999 :path "/"} I’ve also tried to construct .Cookies.SetOptions but it didn’t help

p-himik16:05:21

Looks like it warrants an issue on their GitHub.

p-himik16:05:41

I don't think any of the keys allowed in options should be renamed.

p-himik16:05:21

I think you can hot-fix it in your own code with

(defn ^:export f [^js x]
  (.-maxAge x))

p-himik16:05:03

You don't have to use it - it should simply create an extern for maxAge thus preventing it from being renamed. But I haven't tested this approach.

il-tmfv16:05:49

Thanks! Maybe it is better to write externs manually then? For .Cookies.SetOptions Not a fan of this idea though

p-himik16:05:21

I wouldn't do that myself. I would simply use that workaround above and create an issue on Closure's GitHub that you linked.

dnolen16:05:23

passing #js is not right

dnolen16:05:31

nor is externs

dnolen16:05:46

SetOptions should work and it should be determined why it isn't

dnolen16:05:08

the Closure type annotations tell you that SetOptions is required as 3rd parameter

dnolen16:05:14

@il.tmfv you absolutely cannot call set directly from non-compiled code

p-himik16:05:50

Is it true for Closure API in general? If not, how to tell the difference?

dnolen16:05:32

if that's what you're doing then it's still trivial to fix

dnolen16:05:50

you can write an fn that takes the unmunged parameters and then constructs SetOptions

dnolen16:05:35

@p-himik there's nothing to see here

👍 2
dnolen16:05:44

it's exactly the same for all Closure compiled stuff

il-tmfv16:05:56

How to properly construct it? I’ve tried this, but it feels wrong:

(let [cookie-options (SetOptions.)
        _ (gobj/set cookie-options "maxAge" (* 60 60))
        _ (gobj/set cookie-options "path" "/")]
    (.set goog.net.cookies
          "checkout-data"
          "xxx"
          cookie-options))

p-himik16:05:52

You can use doto to make it more concise and get rid of let.

p-himik16:05:20

And I think you can't use gobj/set here because it has to be munged. Just (set! ...).

dnolen16:05:35

these are the docs, you must supply a type w/ those properties not JSON stuff

dnolen16:05:07

(deftype Options [domain maxAge path sameSite secure])

dnolen16:05:46

or write some Closure JS and import that etc. this is relatively well supported - how transit-js -> transit-cljs works

il-tmfv16:05:39

Thanks! will try and report

p-himik16:05:04

But .Cookies.SetOptions is a type, no? Why wouldn't using

(doto (SetOptions.)
  (set! -maxAge 3600)
  (set! -path "/"))
work?

il-tmfv16:05:07

@dnolen thanks again! deftype helped

p-himik16:05:26

But this works just fine on my end, in :advanced:

(ns app.core
  (:require [goog.net.Cookies :refer [SetOptions]])
  (:import ( cookies)))

(.set cookies "checkout-data" "xxx"
              (doto (SetOptions.)
                (set! -maxAge 31536000)
                (set! -path "/")))

dnolen16:05:51

@il.tmfv or rather you're right that will work too, but the important thing is

dnolen16:05:22

Cookies.SetOptions is defined as an interface here - so you can supply anything that matches

dnolen16:05:43

but yes using SetOptions works instead of creating deftype

dnolen16:05:00

but the takeaway just to drive the point home

dnolen16:05:12

1. For Closure stuff externs is never the right answer

dnolen16:05:28

2. Do not pass runtime stuff to compiled code if you have not established an adapter

p-himik16:05:41

But here https://google.github.io/closure-library/api/goog.net.Cookies.SetOptions.html it says record and not interface. Not sure if Closure treats the terms as interchangeable or there's a discrepancy in documentation.

dnolen16:05:56

pretty sure it can be both?

p-himik16:05:38

In this case - seems like it. And I can find neither documentation nor usage examples on how @record and @interface are different for GCC.

dnolen20:05:55

would nice if there were more engineering / technical details

p-himik20:05:58

Hmm, their demo combines canvas with svg.

phronmophobic20:05:32

I wonder if that just means they're going to use flutter. I think flutter was already canvas based.