Fork me on GitHub

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 ?


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

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


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


it records derefs when converting hiccup -> react elements


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."


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


actually this is the solution


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


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.


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


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


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


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


hmm yeah dunno about that part


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]")


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)


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


What if you return something other than nil?


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


and still the same error


That exact function works for me perfectly...


With the same exact CLJS version.

馃槮 4

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


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


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

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

Drew Verlee21:02:41

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

Drew Verlee21: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.


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)

Drew Verlee22: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


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


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


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


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


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.


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


yea, exactly


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


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


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?


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.


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


So Node has actual shared memory but many browsers do not


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.


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


sure you can but that has a cost


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