Fork me on GitHub
#clojurescript
<
2018-12-08
>
hansw11:12:55

hi all...

hansw11:12:59

Anyone know of an example for js-interop-code for a fragment like this:

Sentry.withScope(scope => {
        Object.keys(errorInfo).forEach(key => {
          scope.setExtra(key, errorInfo[key]);
        });
        Sentry.captureException(error);
      });
It is the Sentry.withScope(scope => ... construct that eludes me a bit

fbielejec13:12:39

Looks like you're looking into writing a Sentry log appender? Maybe this will help: https://github.com/district0x/district-server-logging/blob/master/src/district/server/logging.cljs#L84

jimmy15:12:47

@U8L9BNAJE Does something like this not work?

(.withScope js/Sentry (fn [scope]))

jimmy15:12:24

Never mind. Saw someone else replied.

hansw15:12:05

yep got this working, no prob.

hansw11:12:17

I need to do the above in cljs...

orestis11:12:22

Seems like it expects just a function with a single argument, as a callback, so you can just pass in a normal CLJS function.

orestis11:12:57

Typed on an iPad, please verify (.withScope js/Sentry (fn [scope] ,,,)), replace ,,, with your code.

orestis11:12:06

You might also be able to do (js/Sentry.withScope (fn [scope] ,,,)). Not sure though.

orestis11:12:45

Both approaches assume that Sentry is a global coming from somewhere else, not something you import. No idea about advanced compilation, externs and so on.

hansw11:12:05

yes it is indeed a global, as per the Sentry docs.

hansw11:12:59

what didn't register with me yet is that a cljs function is also a js function πŸ™‚

orestis13:12:39

Yep, that’s a huge value proposition of both Clojure and ClojureScript

orestis13:12:59

(In Clojure functions are runnables)

practicalli14:12:30

What ClojureScript libraries are available that take a very lightweight (in terms of deployment size) approach. React/Reagent/Reframe are excellent, but is there something simpler that is much smaller to deploy in a browser. Thinking something like https://lit-element.polymer-project.org/. Just curious, no actually need at the moment.

practicalli09:12:32

Thanks. We already looked at hoplon, it does take a long time to start up, so had assumed it was as big or bigger than react. Will create a deployment and check the resulting size. Thanks.

flyboarder01:12:31

the time to startup is entirely dependant on your build are you using boot or lein?

practicalli19:12:14

I was just using the getting started example from the Hoplon website, which uses boot. I didnt realise hoplon worked with Leiningen

carocad15:12:04

hey guys, has anybody tried to use externs inference together with nodejs namespace modules? I thought that by using the ns require, the compiler would automatically identify that as an interop type and use the dotform for interop inference but none of my namespace modules are getting inferred so my app breaks on production πŸ˜• any ideas? I know that I am touching muddy waters πŸ˜…

ClashTheBunny16:12:23

Hey, trying to be more cross platform and was wondering what the problem with this is:

cljs.user=> (int \Z)
WARNING: cljs.core/bit-or, all arguments must be numbers, got [string number] instead at line 1 <cljs repl>
0
It seems like it should work, according to the documentation.

ClashTheBunny16:12:41

Okay, so I punted and now I'm using .charCodeAt when in cljs and int when in clj.

ClashTheBunny16:12:31

Now I have an issue with clojure.string/split giving me an empty string at the beginning. Do I have to conditionally filter out the first element of a string when executing in cljs?

mfikes17:12:16

@clashthebunny Can you give an example of the clojure.string/split behavior?

ClashTheBunny17:12:16

So, in Clojure, these are the same:

user=> (map keyword (filter #(not= "" %) (clojure.string/split "abcd" #"")))
(:a :b :c :d)
user=> (map keyword (clojure.string/split "abcd" #""))
(:a :b :c :d)
and in ClojureScript, they are different:
ClojureScript 1.10.439
cljs.user=> (map keyword (filter #(not= "" %) (clojure.string/split "abcd" #"")))
(:a :b :c :d)
cljs.user=> (map keyword (clojure.string/split "abcd" #""))
(: :a :b :c :d)
cljs.user=>

ClashTheBunny17:12:33

See the extra blank symbol at the beginning?

ClashTheBunny17:12:41

It's a known frustration with javascript.

andy.fingerhut17:12:23

It looks like ClojureScript has a separate function clojure.string/split-with-empty-regex to handle the case of an empty regex, which by someone's choice is written to return that empty string first.

andy.fingerhut17:12:19

I do not know the history there, but it might be so that ClojureScript's clojure.string/split is more similar to JavaScript behavior in the empty regex case?

ClashTheBunny17:12:42

What do people normally do to write cljc then? Have a reader conditional that uses split-with-empty-regex in cljs?

mfikes17:12:28

Odd, given that (.split "abc" #"") returns #js ["a" "b" "c"]. There doesn't appear to be any immediately obvious rationale? (No ticket linked...)

mfikes17:12:02

Well, split-with-empty-regex is private, and used inside split

ClashTheBunny17:12:08

Do I need to literally use "/(?:)/" as my regex somehow?

mfikes17:12:00

If perf is no real concern, I would work around with something like (map (comp keyword str) "abcd")

mfikes17:12:01

Geeze, maybe ClojureScript was made to follow an older version of Clojure / Java: https://dev.clojure.org/jira/browse/CLJ-1312

mfikes17:12:28

I'll write up a JIRA so at least the issue can be pondered...

victorb22:12:12

any handy references/tutorials for how to handle events (like .on('error') and similar)

idiomancy22:12:01

beginner cljs node problem if anyone has time..

(ns hello-node-async.core
  (:require  [cljs.core.async :refer [go <!]]))

(def result (atom nil))
(go (reset! result "hello"))
(println "waiting for result....")
(while (not @result))
(println @result)

idiomancy22:12:10

this never prints the result for me. hangs forever

idiomancy22:12:21

I'm not sure why that doesn't work πŸ˜•

orestis22:12:40

Doing a while loop seems wrong, Node is single threaded.

idiomancy22:12:04

I mean yeah, its basically just my way of awaiting the result of the go block. hello-node-async won't go to prod, don't worry!

mfikes23:12:09

A consequence of the single-threaded nature is that once the while loop starts, if the result atom is holding nil, the reset! call can never happen and it will deadlock.

idiomancy23:12:20

ohhhhh wow, okay

idiomancy23:12:23

that's interesting

mfikes23:12:33

@idiomancy FWIW, consider instead

(ns hello-node-async.core
  (:require  [cljs.core.async :refer[go <! put! chan]]))

(def result (chan))
(go (put! result "hello"))
(println "waiting for result....")
(go (println (<! result)))

idiomancy23:12:32

yeah, totally! That's what I would have done in any real scenario anyway, it just bothered me that I didn't know why the while strategy didn't work. It told me that there was something missing from my understanding

royalaid23:12:50

So I already posted this in shadow-cljs but I think people might be interested here too https://clojurians.slack.com/archives/C6N245JGG/p1544313429356100