Fork me on GitHub
#clojurescript
<
2020-06-26
>
arohner09:06:12

I seem to recall a library that would handle lazy loading of data from an API. You specify like “I want user X”, and then the data is lazily loaded into datascript or something like that. Does that ring any bells?

William Steinberg10:06:22

Greetings, I am a newbie with ClojureScript. Have 40+ years experience as a developer. Will need to know how to interop with custom JavaScript/TypeScript files.

millettjon13:06:52

In general it is easy. See the JavasScript interop section at https://cljs.info/cheatsheet/ for an overview. There are a lots of google results with more detail.

Sung13:06:43

Is there a standard way/a guide on best practices for porting clojure programs to cljc programs?

Casey14:06:04

Is anyone aware of a clojure.core.memoize impl for clojurescript?

dpsutton14:06:25

cljs.core has a version of memoize. Are you looking for something else?

dpsutton14:06:45

(defn memoize
  "Returns a memoized version of a referentially transparent function. The
  memoized version of the function keeps a cache of the mapping from arguments
  to results and, when calls with the same arguments are repeated often, has
  higher performance at the expense of higher memory use."
  [f]
  (let [mem (atom {})]
    (fn [& args]
      (let [v (get @mem args lookup-sentinel)]
        (if (identical? v lookup-sentinel)
          (let [ret (apply f args)]
            (swap! mem assoc args ret)
            ret)
          v)))))

Casey14:06:43

Yea, I find myself needing the ttl and fifo caches from clojure.core.memoize

dpsutton14:06:10

ah. ha. that slash to period made a huge difference

Casey14:06:57

Yea, haha, sorry. I'm aware of cljs.core/memoize but I'm asking about the library with a nearly identical name https://github.com/clojure/core.memoize

dpsutton14:06:23

i would look towards npm for this one. i remember reading some source and amazon had some caches. i bet there's a nice version out there. are you using shadow?

Casey14:06:01

I am using shadow, yes. Good idea, I'll take a look.

Casey14:06:29

Just curious, is there an impl reason those libraries don't exist for cljs? Or is it just lack of demand/need?

dpsutton14:06:55

i bet they predate clojurescript and then there was never a demand for them or someone to work on porting

nickbauman16:06:33

I saw that the clojurescript repo was last touched 6 years ago? Is that possible?

nickbauman16:06:23

Nope, wrong.

nickbauman16:06:44

8 days ago 😊

milgra16:06:48

Hi All, I've just finished my game in ClojureScript/WebGL and would like to share what have I learned/experienced during the process. Cljs-Brawl ( https://github.com/milgra/cljs-brawl ) is a total rewrite of Brawl written in C/OpenGL ( https://github.com/milgra/brawl ) I was curious about two things : - how do you structure a complex game like this in clojure, a super compact stateless lisp language? - will it be fast enough? javascript is already slow, how will clojure slow down things? ClojureScript is fast enough but converting cljs types to javascript types is really slow. Conversion should be avoided but if it's unavoidable you better use javascript types from the beginning. I had to do it with vertex collection into js arraybuffers. Clojure code Compared to the C equivalent of the game : C - 18500 lines, 740000 characters ( excluding the low level frameworks that are present in html5/javascript) Clojure - 7000 lines, 210000 characters The clojure code size is roughly the third of the C code size. Most common pattern dilemmas : 1. One complex reducer function or multiple simple threaded reducers ( aka transducers )? The second solution wins in clarity and readability altough it needs multiple iterations instead of one. If you also filter out items with every step then the speed should be almost identical. 2. Extract sub-data for a function or pass the whole dataset and let the function extract and re-insert data for itself It's hard to decide. In higher parts of a program the second version results in a cleaner code, caller functions are cleaner and callees are all right but in case of lower parts it is overkill, for example you don't want to extract x and y components of vectors from the whole state in an add-vector function.

jjttjj17:06:13

Wow this looks awesome!

Sung17:06:08

Is there a clojure-like eval function in clojurescript?

noisesmith17:06:10

the clojurescript compiler does not emit code that's capable of compiling at runtime, no.

noisesmith17:06:41

there are projects like lumo and planck that are built on cljs and can also compile cljs themselves without a java process

noisesmith17:06:33

both are for back end only though (lumo uses the node engine, planck uses os js apis for each platform)

phronmophobic17:06:14

it is possible to compile clojurescript in the browser (and call eval), but it's a pain and full of dragons.

3
lilactown18:06:05

this is called “self hosted” ClojureScript and there are guides out there

3
Sung06:06:54

Thanks for the help!

noisesmith18:06:36

oh TIL thanks

Raymond Ko21:06:33

Hello, I am getting this issue:

(-> (.queryStream db sql sql-args)
               (.on "error" on-error)
               (.on "data" on-data)
               (.on "end" on-end))
is being compiled as
return (e, f).xi("error", y).xi("data", v).xi("end", r);
db is a node.js library (MariaDB node.js connector). Am I doing something undefined? I am using shadow-cljs, and I am trying to figure out why Google Closure at the advanced optimization level is renaming the .on method? I am also noticing that the initial call (.queryStream class-instance) is getting mis-compiled. db is a new instance of a JS class.

Raymond Ko21:06:56

I changed my optimization settings to :simpleand it compiled correctly. Does anyone have a list of things to try and look for to diagnose things like this?

Toni Dahl18:06:08

@raymond.w.ko I happened to write a small blog post on this particular subject, if you are interested: https://dev.solita.fi/2020/06/25/taming-cljs-advanced-compilation.html

🎉 6
phronmophobic18:06:37

you might want to include a link to https://clojurescript.org/guides/externs. Is there a resource on what :infer-externs actually does?

Toni Dahl18:06:13

Externs guide gives a good overview of :infer-externs, but I am not currently aware of any better resource.

Toni Dahl18:06:01

But, I will add that missing link. Thanks @smith.adriane

phronmophobic21:06:14

I'm not an expert on this, but you'll probably need an externs file for this library

phronmophobic21:06:10

Externs Inference is new (to me), https://clojurescript.org/guides/externs#externs-inference, but I might start there

Raymond Ko22:06:25

Okay, I fixed it. Thank you @smith.adriane . Looking at shadow-cljs documentation, I can add a ^jsin front of the db variable to make it an extern. Then it compiles correctly.

phronmophobic22:06:49

that's pretty awesome. cljs tooling has improved a lot since when I started using it.

Raymond Ko22:06:56

The strange thing is that I didn't do it for other usages of db elsewhere, yet the compiler knew not to rename.

Christopher Gsell23:06:23

Hi everyone, I am trying to make a file-chooser dialogue box in clojure script. I didn’t have any success with JFileChooser, so I tried using seesaw, but I couldn’t even implement (use ‘seesaw.core). Does anyone know if seesaw is still up to date or if there’s another library I can use?

noisesmith23:06:16

clojurescript can't use seesaw, because seesaw is a jvm clojure lib

noisesmith23:06:10

are you sure you want clojurescript? if so you can use a javascript library, or a helper for constructing the DOM like re-frame

Christopher Gsell23:06:00

Ahh okay that makes sense. I think I want to use clojure script because I’m making a website and everything else is in clojure script. I’ll check to see if JavaScript library has something similar to jfilechooser. Thank you!

noisesmith23:06:14

here's a thread describing how to make a file chooser in re-frame https://groups.google.com/g/clojurescript/c/xB_ul9HrtiE?pli=1

noisesmith23:06:44

there are other frontend frameworks, but most of us use them, rather than using js browser features or libs directly

Christopher Gsell23:06:46

Thank you so much!