clojurescript

ClojureScript, a dialect of Clojure that compiles to JavaScript http://clojurescript.org | Currently at 1.10.879
Nazral 2021-01-31T03:56:02.242600Z

I have to handle quite a lot of text data and do some computationally expensive operations on it (parsing and building a data structure from it), so I want to use a webworker for that, but it seems like there is no simple way to pass a cljs data structure from the main thread <-> webworker, should I be using something like https://github.com/mfikes/cljs-bean for serialization/deserialization ?

Nazral 2021-01-31T03:56:11.242900Z

or are there better ways

Nazral 2021-01-31T04:12:26.243200Z

Because js->clj doesn't seem to work in this case

dpsutton 2021-01-31T04:18:29.244Z

try clj-&gt;js when sending and js-&gt;clj when receiving?

Nazral 2021-01-31T04:23:28.244100Z

I did to no avail. I'm not home atm so I cannot show the error, will do when I come back

phronmophobic 2021-01-31T05:28:13.244700Z

if you're trying to serialize cljs data in the browser, you should check out https://github.com/cognitect/transit-cljs

Nazral 2021-01-31T16:54:47.270500Z

will check it out thanks

Fredrik Andersson 2021-01-31T12:09:44.246600Z

Hi, I have a problem using Clojurescript, Figwheel and now trying to add firebase to my project. I get this: [Figwheel:WARNING] Could not Analyze: Could not locate cljs/core/async/macros__init.class, cljs/core/async/macros.clj or cljs/core/async/macros.cljc on classpath.

Fredrik Andersson 2021-01-31T12:11:15.248200Z

I am new to clojure and clojurescript and was thinking about moving from Vue into reagent

Fredrik Andersson 2021-01-31T12:12:19.248700Z

I don't understand why this problem came when I added firebase to my package.json

Fredrik Andersson 2021-01-31T12:14:53.249500Z

i tried to remove firebase but the problem is still there. now I have no idea at all

Fredrik Andersson 2021-01-31T12:17:45.249900Z

sorry for bothering you, i found out why :man-facepalming:

p-himik 2021-01-31T12:57:49.250Z

It's probably not related to Firebase at all. Try adding org.clojure/core.async to your dependencies.

p-himik 2021-01-31T12:58:03.250200Z

Ah, I missed the "found out" part. :) What was it?

Fredrik Andersson 2021-01-31T12:58:34.250400Z

yeah, I found out that I did remove the dependecy while still require the async macros

👍 1
Fredrik Andersson 2021-01-31T13:00:10.251800Z

I'm having a hard time getting a project up with my components that I need.

Fredrik Andersson 2021-01-31T13:02:12.253400Z

i have a project up and running with figwheel now. However, I can't seem to use Firebase API

Fredrik Andersson 2021-01-31T13:02:54.253900Z

should I try to set up a new project using shadow-cljs?

p-himik 2021-01-31T13:29:32.254Z

Since you're just starting with CLJS, I would recommend it, yes. Personally, I had almost 0 problems with it. And the ones that I did have were caused by my unconventional usage patterns, not by the tool itself.

Fredrik Andersson 2021-01-31T13:47:02.254200Z

it seems to be easier to use "native" libs with shadow-cljs

Fredrik Andersson 2021-01-31T13:48:12.254400Z

want to make a prof of concept migration to clojurescript to get rid of our Vue-spaghetti

p-himik 2021-01-31T13:52:58.254900Z

Yes, I have found it much easier to use JS libs with shadow-cljs. I've never tried figwheel-main though and some people say that it's just as good. But its documentation is not that great and I still occasionally see reported issues being mentioned.

hadils 2021-01-31T14:03:27.259Z

Hello I am using shadow-cljs for a react native application. Every is working except for hot code reload on my iPhone simulator. I have disabled Expo fast refresh but I still have to reload manually after recompiling.

Atiq Gauri 2021-01-31T16:00:26.262800Z

Hey guys... Need some help with using sourcemap on http://sentry.io I have this electron app written with cljs and generate sourcemap at with shadow-cljs. I have uploaded them successfully to sentry and but they don't seems to work there: I think it is not working because sourcemap files contain cljs namespaces but sentry error files doesn't... please can anyone help me with this?

Fredrik Andersson 2021-01-31T16:35:49.264800Z

Now I have a shadow-cljs project running. I have added Firebase to the package.json but I just can't call Firebase.initializeApp

Fredrik Andersson 2021-01-31T16:35:59.265200Z

I'm not sure what I am doing wrong

Fredrik Andersson 2021-01-31T16:36:16.265400Z

TypeError: module$node_modules$firebase$dist$index_esm.initializeApp is not a function

Fredrik Andersson 2021-01-31T16:47:28.265900Z

(ns <http://percap.admin.app|percap.admin.app>
  (:require [reagent.dom :as dom]
            ["firebase/app" :as firebase]
            ["firebase/firestore"]))

(defonce firebase-instance (atom nil))

(defn init-firebase [config]
  (when-not @firebase-instance
    (reset! firebase-instance (firebase/initializeApp (clj-&gt;js config)))))
This is my code

Fredrik Andersson 2021-01-31T16:48:32.266800Z

I have also tried

(ns <http://percap.admin.app|percap.admin.app>
  (:require [reagent.dom :as dom]
            ["firebase" :as Firebase]))

(defonce firebase-instance (atom nil))

(defn init-firebase [config]
  (when-not @firebase-instance
    (reset! firebase-instance (-&gt; Firebase (.initializeApp (clj-&gt;js config))))))

Fredrik Andersson 2021-01-31T16:49:05.267500Z

ok thanks!

thheller 2021-01-31T16:49:08.267600Z

it might be :default firebase and (.initializeApp firebase ...)

thheller 2021-01-31T16:49:20.268300Z

see the section about default export and how to test it in the REPL

Fredrik Andersson 2021-01-31T16:49:44.268800Z

ah, right! i saw something about :default before when i was in figwheel-land

Fredrik Andersson 2021-01-31T16:50:02.269300Z

back then that didn't work obviously, but now it should

Fredrik Andersson 2021-01-31T16:51:24.269600Z

😄 thanks!

thheller 2021-01-31T16:52:14.269800Z

it might be. I don't have a clue.

Fredrik Andersson 2021-01-31T16:52:29.270300Z

it works now with :default

👍 1
thheller 2021-01-31T16:55:19.270700Z

this is most likely caused by the emulator not being able to connect back to the shadow-cljs process

thheller 2021-01-31T16:55:24.270900Z

maybe it picked the wrong IP or so

thheller 2021-01-31T16:55:36.271100Z

run shadow-cljs watch app --verbose and it'll log the IP it used on start

thheller 2021-01-31T16:55:49.271300Z

verify that is the correct one

thheller 2021-01-31T16:56:22.271500Z

you can easily try connecting to the shadow-cljs process on that IP with port 9630 via a browser in the emulator

thheller 2021-01-31T17:01:09.271800Z

it appears that you are maybe mixing outputs. the left is from a development build but the right seems to be from a release build?

thheller 2021-01-31T17:01:54.272Z

only release builds are self-contained and have a chance to work with sentry. no clue how sentry handles development builds.

hadils 2021-01-31T17:08:20.272200Z

Thank you for your help @thheller!

Atiq Gauri 2021-01-31T17:47:13.272400Z

Yes you are right...

Atiq Gauri 2021-01-31T17:48:46.272600Z

source maps are uploaded from dev build

Atiq Gauri 2021-01-31T17:49:21.272800Z

but will sentry pickup even with .background and other prefix in file name?

thheller 2021-01-31T17:49:52.273Z

so I don't use sentry or develop electron apps so I do not have a clue

Atiq Gauri 2021-01-31T18:04:31.273400Z

Thanks man!! you hinted me in right direction... release command for electron create one single master main.js and main.js.map and that will solve our problem

John Doneth 2021-01-31T18:10:20.275Z

Does anyone know if it's possible to perform an effect when the number of views depending on a subscription reaches zero? Specifically with re-frame.

p-himik 2021-01-31T18:19:18.275100Z

#re-frame is a better place for such questions. You can add such a handler with re-frame.interop/add-on-dispose!. I don't think it's a public API though. I'm also pretty sure that the fact that subs are disposed of as regular atoms when their views no longer need them is an implementation detail, so be aware.

John Doneth 2021-01-31T18:22:37.275300Z

Oh thank you. I didn't see that channel. Thanks for the pointer as well

👍 1
p-himik 2021-01-31T18:27:17.275600Z

This will probably be useful to you as well: https://day8.github.io/re-frame/FAQs/LoadOnMount/ Since what you want is somewhat conceptually similar.

John Doneth 2021-01-31T18:31:40.275900Z

Hmm maybe. What I'm trying to do is unsubscribe from a re-graph subscription when it's no longer necessary. The re-graph subscription is started when the view subscription is initiated. I was looking for a way to clean up the graphql subscription when the user moves to another page and no longer needs that information kept live in the app-db.

p-himik 2021-01-31T18:34:05.276100Z

What does "subscribing to a re-graph subscription" mean exactly? If it's a regular re-frame sub, then it will all be done automatically.

John Doneth 2021-01-31T18:36:14.276300Z

The re-graph subscription opens a websocket connection to a graphql server and receives events as a stream which get handled by a reg-event-db handler. My concern is that the stream will be kept open and processing events after the user no longer cares for them.

p-himik 2021-01-31T18:37:14.276500Z

Is there any code in re-graph that closes that connection?

John Doneth 2021-01-31T18:37:37.276700Z

It appears that it's a manual effect

;; stop the subscription
(re-graph/unsubscribe :my-subscription-id)

p-himik 2021-01-31T18:40:13.276900Z

Ah, they're following the re-frame documentation that I linked above. There are events, :re-graph.core/subscribe and :re-graph.core/unsubscribe, and you should dispatch them when you need and don't need the data. As soon as you stop focusing on views, it will all become clear.

p-himik 2021-01-31T18:41:21.277100Z

A hint in advance - if you have multiple events that make a single view appear and you don't want to change all those events, you can use a single global interceptor for that which would monitor something like a single :is-that-view-visible? flag in the app-db and dispatch the right re-graph event when the flag's value is changed.

John Doneth 2021-01-31T18:50:48.277300Z

Makes sense. Thanks for the help!

p-himik 2021-01-31T18:51:19.277500Z

NP

Fredrik Andersson 2021-01-31T20:35:28.278300Z

I wonder how I would check if a property or function is defined on a native JS object?

p-himik 2021-01-31T20:47:09.278400Z

(not (undefined? (.-prop obj)))

Fredrik Andersson 2021-01-31T20:49:58.278600Z

thanks, didn't know about undefined

currentoor 2021-01-31T21:24:52.279600Z

I know js* is an internal thing that we're not supposed to use but is there any documentation on how it works? I couldn't find a blog post or anything.

thheller 2021-02-01T08:29:09.280100Z

documenting it would lead to people using it so its not 🙂

currentoor 2021-02-01T18:19:56.286800Z

lol

currentoor 2021-02-01T18:41:04.288300Z

but it's likely not going away any time soon

thheller 2021-02-01T19:03:24.288500Z

yes but people almost always use it for the wrong reasons. at least all the occasional mentions I've seen in this channel were abusing stuff that shouldn't be done 😛

thheller 2021-02-01T19:04:19.288800Z

js* really doesn't do much, just takes the string you give it and placed it into the output as is. optinally interpolating some values

thheller 2021-02-01T19:04:42.289200Z

(js* "some(~{})" "foo") would give you some("foo") in the code

currentoor 2021-02-01T19:28:51.302700Z

ah i see

currentoor 2021-02-01T19:29:39.302900Z

thanks!

thheller 2021-02-01T19:32:51.303100Z

what are you up to? 😛

currentoor 2021-02-03T22:33:21.410500Z

oh I'm actually not using it for anything, just pure curiosity