Fork me on GitHub
#clojurescript
<
2021-01-31
>
Nazral03:01:02

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 ?

Nazral03:01:11

or are there better ways

Nazral04:01:26

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

dpsutton04:01:29

try clj->js when sending and js->clj when receiving?

Nazral04:01:28

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

phronmophobic05:01:13

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

Nazral16:01:47

will check it out thanks

Fredrik Andersson12:01:44

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 Andersson12:01:15

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

Fredrik Andersson12:01:19

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

Fredrik Andersson12:01:53

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

Fredrik Andersson12:01:45

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

p-himik12:01:49

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

p-himik12:01:03

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

Fredrik Andersson12:01:34

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

👍 3
Fredrik Andersson13:01:10

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

Fredrik Andersson13:01:12

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

Fredrik Andersson13:01:54

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

p-himik13:01:32

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 Andersson13:01:02

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

Fredrik Andersson13:01:12

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

p-himik13:01:58

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.

hadils14:01:27

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.

thheller16:01:19

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

thheller16:01:24

maybe it picked the wrong IP or so

thheller16:01:36

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

thheller16:01:49

verify that is the correct one

thheller16:01:22

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

hadils17:01:20

Thank you for your help @U05224H0W!

Atiq Gauri16:01:26

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?

thheller17:01:09

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?

thheller17:01:54

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

Atiq Gauri17:01:13

Yes you are right...

Atiq Gauri17:01:46

source maps are uploaded from dev build

Atiq Gauri17:01:21

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

thheller17:01:52

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

Atiq Gauri18:01:31

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

Fredrik Andersson16:01:49

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 Andersson16:01:59

I'm not sure what I am doing wrong

Fredrik Andersson16:01:16

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

Fredrik Andersson16:01:28

(ns 
  (: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->js config)))))
This is my code

Fredrik Andersson16:01:32

I have also tried

(ns 
  (:require [reagent.dom :as dom]
            ["firebase" :as Firebase]))

(defonce firebase-instance (atom nil))

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

thheller16:01:08

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

thheller16:01:20

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

Fredrik Andersson16:01:44

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

Fredrik Andersson16:01:02

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

thheller16:01:14

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

Fredrik Andersson16:01:29

it works now with :default

👍 3
John Doneth18:01:20

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-himik18:01:18

#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 Doneth18:01:37

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

👍 3
p-himik18:01:17

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 Doneth18:01:40

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-himik18:01:05

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 Doneth18:01:14

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-himik18:01:14

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

John Doneth18:01:37

It appears that it's a manual effect

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

p-himik18:01:13

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-himik18:01:21

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 Doneth18:01:48

Makes sense. Thanks for the help!

Fredrik Andersson20:01:28

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

p-himik20:01:09

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

Fredrik Andersson20:01:58

thanks, didn't know about undefined

currentoor21:01:52

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.

thheller08:02:09

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

currentoor18:02:04

but it's likely not going away any time soon

thheller19:02:24

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 😛

thheller19:02:19

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

thheller19:02:42

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

thheller19:02:51

what are you up to? 😛

currentoor22:02:21

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