Fork me on GitHub
#clojurescript
<
2020-08-11
>
bones01:08:12

Has the quick-start page changed? I thought it included stuff about doing “manual” builds through the cljs.build api?

Jack Arrington02:08:08

I know it’s the case in Clojure, but in CLJS is there a performance benefit to using protocols over multimethods for simple type-based polymorphism? I get that protocols would probably be more idiomatic in this case regardless, just curious about the implementation.

quadron07:08:37

how do i capture a required value in clojurescript? something like the following:

import EthCrypto from 'eth-crypto';
const EthCrypto = require('eth-crypto');

Old account11:08:33

Hello! what is the analogy of this import AdyenDropIn from 'react-native-adyen-drop-in' to Clojurescript ?

Karol Wójcik12:08:35

@stebokas (:require ["react-native-adyen-drop-in" :default AdyenDropIn]) in shadow-cljs

dnolen13:08:43

note that in the next release there will be a portable way to do that and a few other things

dnolen13:08:40

@mail985 yes, same as Clojure more or less

dnolen13:08:15

@bones yes it was updated a couple of years ago

gomosdg15:08:49

Hi, I am using lein-figwheel and I am trying to require a js libray. When I do I get the following error:

cljs.user=> (require '[aws-amplify :as aws])
ERROR: JSC_LANGUAGE_FEATURE. This language feature is only supported for ECMASCRIPT8 mode or better: async function. at /home/gomotso/navigare/navigator/node_modules/idb/build/esm/index.js line 63 : 19
ERROR: JSC_LANGUAGE_FEATURE. This language feature is only supported for ECMASCRIPT8 mode or better: async function. at /home/gomotso/navigare/navigator/node_modules/idb/build/esm/index.js line 71 : 12
ERROR: JSC_LANGUAGE_FEATURE. This language feature is only supported for ECMASCRIPT2018 mode or better: object literals with spread. at /home/gomotso/navigare/navigator/node_modules/idb/build/esm/index.js line 78 : 4
Can someone please help?

rberger20:08:58

I wrote up a tutorial on using AWS Amplify and Clojurescript a little while ago. Learnt a lot since then but I think its still useful https://dev.to/rberger/aws-amplify-and-clojurescript-re-frame-part-1-3d3f

chucklehead20:08:52

the react components have changed since then, I had issues with @aws-amplify/ui-react where your guide is using aws-amplify-react

chucklehead20:08:06

forgot I'd put this together...the versions are probably out of date now, but basic repro here where the only difference is the version of the amplify components

Sam Ritchie17:08:47

Hey all! I'm working on porting a physics engine from clojure to clj: https://github.com/littleredcomputer/sicmutils, and was wondering if anyone had any suggestions for a possible way to add (and customize) ratio literal handling to cljs?

Sam Ritchie17:08:13

The goal would be to re-map a ratio literal to a https://github.com/infusion/Fraction.js object... I know that I can make my own tagged literal,

Sam Ritchie17:08:42

and have it work in both clj and cljs. But maybe there's some in-browser repl environment someone's seen that pre-processes ratios

cjsauer17:08:45

Is there a cljs compatible equivalent of the clojure/core.memoize lib?

cjsauer17:08:47

That’s the memoize function yea. I’m looking for a cljs compatible implementation of this lib: https://github.com/clojure/core.memoize

Sam Ritchie17:08:49

ah! got it, sorry about that

athomasoriginal17:08:41

Is it possible to swap out the version of google closure library used by ClojureScript for a specific project vs. the default one used bu CLJS? Not for production, just curious.

dnolen18:08:05

yes, though you have to be careful

dnolen18:08:28

tooling often has subtle dependencies on Google Closure Library

👍 3
athomasoriginal18:08:44

Can we do this through deps.edn or is the process a little more involved?

Alex Miller (Clojure team)18:08:17

you can use an alias with :override-deps to do this in deps.edn

athomasoriginal18:08:11

Oh nice, I think I was overthinking how google-closure-library is usually consumed by a JS app. Cheers!

athomasoriginal20:08:17

@dnolen Do ya’ll still use https://github.com/clojure/clojurescript/blob/master/script/closure-library-release/closure-library-release.sh to package the google closure library as a maven project? Or is there another common way to package that up?

bones22:08:38

hahaha time flies. Thanks @dnolen

Kasey Speakman22:08:47

Easily fixable.

phronmophobic22:08:57

what's the batching buffer doing? is it just accumulating items into a single collection? if so, I think a transducer with the traditional buffers would probably be a better fit

Kasey Speakman22:08:58

I was thinking more about the constraints of ClojureScript since it is written for Clojure

Kasey Speakman22:08:29

Transducers add latency for sparse messages. The idea is to process a batch of messages in one go.

Kasey Speakman22:08:41

Rather than pick one off at a time.

phronmophobic22:08:45

the implementation uses a ref, which doesn't exist in js land, but since js is single threaded, you could just replace the ref with an atom. I'm not sure that makes it a good idea

phronmophobic22:08:02

there's a transducer called partition-all that effectively does the same thing. I haven't done any profiling, but I would guess that using the partition-all transducer would perform as well or better

Kasey Speakman22:08:10

using take or a batching transducer would make it wait until n messages were available or a timeout before delivering them. (more latency). versus the message processor when it has control saying "give me everything you have right now (up to N)".

phronmophobic22:08:40

I would probably still put that logic on the "outside" of the buffer, but the implementation would depend on how you would handle overflow (ie. producers producing faster than consumers consume)

phronmophobic22:08:17

but to answer your original question, you could translate the clj version to cljs by simply replacing the ref with an atom

phronmophobic22:08:28

> "give me everything you have right now (up to N)". this can be implemented using any channel/buffer combo with:

(loop [chunk []
       n 5]
  (if (pos? n)
    (if-let [val (async/poll! ch)]
      (recur (conj chunk val) (dec n))
      chunk)
    chunk))

Kasey Speakman22:08:05

doesn't each poll incur some rendezvous overhead?

Kasey Speakman23:08:08

Seems a workable solution, but a batch would be better.

Kasey Speakman23:08:18

Is why re-frame implements its own work queue. But I thought it would be better if I could make it work with core async. And found that batching buffer.

phronmophobic23:08:01

I probably wouldn't worry too much about the nitty gritty performance aspects and just use the solution that makes the most logical sense. you can get pretty far by just writing straightforward code, http://swannodette.github.io/2013/08/02/100000-processes/

Kasey Speakman23:08:45

At this point in my career, I try to align performance with the semantics of my problem where I can. Porting a batching buffer seems a small price to pay to get that alignment. And it beats writing my own queue processor (which was my initial instinct) as in re-frame.

👍 3
Kasey Speakman23:08:22

Thank you for your help!

Kasey Speakman23:08:59

(I am experienced, but new to Clojure)

parrot 3
phronmophobic16:08:47

looks great! > In fact I'm a bit scared because it just worked the first time. :rolling_on_the_floor_laughing:

❤️ 3