Fork me on GitHub
#clojurescript
<
2020-02-24
>
kulminaator08:02:30

i'm pretty sure there's a way to have a in-browser repl (e.g. in a popup window , with some limited backward scrolling ability) , to use with a in-browser clojurescript app .. but i'm having difficulties finding one... any good suggestions ?

introom09:02:11

(def name  (reagent.ratom/atom "Bear"))

(defn ask-for-forgiveness
  []           ;; <--- no props     
  [:div "Please " @name " with me"])   ;; notice that @

introom09:02:33

How does reagent knows which function to re-render when the depending ratom changes ?

thheller10:02:11

it records derefs when converting hiccup -> react elements

Audrius12:02:01

Hello! who has an ide why this custom CLJS reader does'n work for me:

(ns ok.ok)

;; #js-object-record                                                                               
(defrecord JsObjectRecord
    [type data-map]) 

(defn js-obj-read-fn [arg]
    (println "reading function-----" arg (type arg)))

(cljs.reader/register-tag-parser! 'ok.ok/JsObjectRecord js-obj-read-fn)
(cljs.reader/read-string "#ok.ok/JsObjectRecord [1 2]")
(println (cljs.reader/read-string "#ok.ok/JsObjectRecord [1 2]"))
I am having : "No reader function for tag ok.ok/JsObjectRecord."

thheller13:02:35

depending on which CLJS version you are using it might expect a string

Audrius14:02:55

actually this is the solution

thheller13:02:48

(cljs.reader/register-tag-parser! "ok.ok/JsObjectRecord" js-obj-read-fn)

p-himik13:02:54

Huh. I'm trying it in my own namespace and it fails with No dispatch macro for h.. h is the first character in that namespace.

thheller13:02:37

then you have the version that requires a symbol ...

thheller13:02:54

I forgot which version that was changed but it was a breaking change

p-himik13:02:26

Yeah, I did use the symbol version. But it seems that a tag parser cannot return nil.

p-himik13:02:58

If I return nil it thinks that that's not a tag and tries to parse it as a dispatch macro.

thheller13:02:47

hmm yeah dunno about that part

Audrius14:02:07

I use [org.clojure/clojurescript "1.10.597"] and for example this code works:

(cljs.reader/register-tag-parser! 'foo identity)
(cljs.reader/read-string "#foo [1 2]")

Audrius14:02:16

but for some reason when I namespace the symbols it stops, even if the namespace is already present (I created one just for the sample)

Audrius14:02:49

I just found out that the reading function is the problem - when I use identity it all works, but any function made by me drops that exception

p-himik14:02:58

What if you return something other than nil?

Audrius14:02:02

(defn js-obj-read-fn [arg] (println "reading function-----" arg (type arg)) arg)

Audrius14:02:11

and still the same error

p-himik14:02:29

That exact function works for me perfectly...

p-himik14:02:45

With the same exact CLJS version.

馃槮 4
Audrius14:02:12

does this (cljs.reader/register-tag-parser! "jsc" js-obj-read-fn) return anything?

Audrius14:02:53

I restarted the REPL and it works now....

p-himik14:02:31

Heh, yeah, that happens. I usually work within web pages, and I tend to just reload the page when something strange is going on.

馃憤 4
kaffein15:02:35

hey people!! has anyone ever managed to play with cordova + cljs please ? I would be interested in some documentation on how to get them to work together!thanks in adv

drewverlee21:02:41

the translation of foo.init().then(function(z) { z }); would be (.then (.init foo) (fn [z] z)) right?

drewverlee21:02:23

yep. Apparently the api returns some other thing that isn't a promise if you don't tell it to. A "librarly specific object". cool.

位ustin f(n)22:02:36

I am trying to have some calculations work out exactly the same between Clojure and Clojurescript, and the different implementations of numbers are biting me. Are there any libraries or quick fixes for this? Otherwise my first thought is to make my own 'Ratio' type and math functions to use cross-platform.

cjsauer22:02:37

I recently watched a video by Tony Kay where he uses big.js to help bridge the gap between big decimals in Clj/Cljs. It鈥檚 around the 11 minute mark in this video (I think...on mobile currently) https://youtu.be/euwuLyzMDVg

drewverlee22:02:25

I feel like that question is going to be a rabbit hole 馃檪

位ustin f(n)22:02:01

If it makes thinks any better, I don't have to mess with how numbers work everywhere they might be used in clojurescript, just in a limited 'scripting' scope I have total control of.

位ustin f(n)22:02:25

I have been avoiding this one for months, but my internal users are not satisfied with my 'just use integers' solution

andy.fingerhut00:02:13

I guess they wouldn't be satisfied with a 'just use doubles' solution, either, which I think is what some JavaScript engines default to.

Kamuela22:02:01

Often told JS isn鈥檛 multithreaded, but is anyone looking at bringing more over into CLJS utilizing Worker threads?

thheller22:02:08

workers can't share memory so they aren't super useful for most stuff

4
thheller22:02:45

in the shadow-cljs UI I moved all data processing to a worker and the "main" thread just queries it like a db. works ok but the tradeoffs are kinda annoying

isak22:02:45

Once I made a game where I tried moving the physics to a webworker, but it cut FPS from 60 to 20. Having to serialize everything all the time means it is useless for a lot (maybe even most) use cases.

lilactown22:02:54

will be cool if workers + wasm threads get to some point where we could pass immutable objects without serializing

isak22:02:31

yea, exactly

isak22:02:10

another big limitation is you cannot do DOM measurements in a web worker

lilactown22:02:27

I don鈥檛 know much but my first thought is that will always be impossible to do without coordinating with the main thread

isak22:02:33

well for example on other platforms, it is not problem to measure the size of a text with a certain font on a background thread. No reason one shouldn't be able to do the same in a web worker. I could see limiting which thread can modify the DOM, but what about DOM objects that are just in memory, not rendered on screen?

Kamuela23:02:17

Is this something not shared on the browser? > Unlike child_process or cluster, worker_threads can share memory. They do so by transferring ArrayBuffer instances or sharing SharedArrayBuffer instances.

lilactown23:02:00

AFAICT SharedArrayBuffer is caught in limbo right now and isn鈥檛 supported by many browsers

Kamuela23:02:27

So Node has actual shared memory but many browsers do not

thheller10:02:57

It does not. it has shared memory buffers. basically blobs of binary data. you still need to serialize /deserialize everything which is the main overhead. so you can't just put JS objects in there and "share" them.

Kamuela13:02:09

Ok, but can鈥檛 that still be abstracted around?

thheller13:02:04

sure you can but that has a cost

isak23:02:51

doesn't seem like the most useful form of shared memory anyway