Fork me on GitHub
Kasey Speakman01:08:15

Ported, still have to test usage.

(deftype BatchingBuffer [items n]
  (full? [this]
    (>= (count @items) n))
  (remove! [this]
    (let [[old new] (reset-vals! items [])]
  (add!* [this item]
    (swap! items conj item))
  (close-buf! [this])
  (-count [this]
    (if (empty? @items)

(defn batching-buffer [n]
  (BatchingBuffer. (atom []) n))

Kasey Speakman06:08:15

I take a file, copy (or move and rename, tried both) it into a subfolder under main, change the require appropriately (folder.file instead of just file). And then I get Cannot read property 'cljs$core$IFn$_invoke$arity$2' of null in the ClojureScript app. using shadow-cljs. Any common thing that trips up newcomers that results in that?

Kasey Speakman06:08:42

Got it working. Something to do with namespaced keys

Artem Bezlyubchenko09:08:05

Hi guys, I have wrapper around require :

(defn load [path]
    (js/require (str path))
    (catch :default _ nil)))
and :optimizations :advanced So I get an error: Invalid call at line 1478: require(q.a(a)) May anyone help, please?)

Artem Bezlyubchenko09:08:01

If I don’t use str path , I would have Invalid module: path`. js/require can only process strings`

Artem Bezlyubchenko09:08:36

I tried ^string , but no luck


in which context do you use this? require is often a compile time constant and cannot be used dynamically. eg. webpack, react-native, etc.


only place you can use it dynamically is node pretty much

Artem Bezlyubchenko09:08:13

I use it with Expo (ReactNative) to load images from assets…

Artem Bezlyubchenko09:08:14

I have a crash, when asset cannot be downloaded, so decided to go with a wrapper


yeah you can't. the JS tools need to be able to read the require calls at compile time


so only (js/require "../assets/as-a-string.png") or so works

Artem Bezlyubchenko09:08:12

Thanks @U05224H0W. Any ideas how not to crash on Could not download from ?)


I don't know. I don't do react-native dev myself. maybe it can only use local files? check the expo/metro docs.

Artem Bezlyubchenko12:08:22

@U05224H0W The interesting thing is - wrapper works locally, when I don’t do cljs optimizations


I'm trying to put a CodeMirror editor in a reagent app, but am falling at an early hurdle. I've required codemirror with

(:require [reagent.core :as r]
            ["codemirror" :as codemirror])
following example (and a couple of others) I'm trying to do something like
(reset! cm (js/CodeMirror. (.createElement js/document "div")
                           (clj->js {})))
but I get a 'CodeMirror is not defined' I also tried codemirror/CodeMirror. in place of js/CodeMirror. but there I got CodeMirror is not a constructor - so it at least seems to be finding the class in that case. Is there some missing require thing I need to do before I can use js/CodeMirror.?


@allaboutthatmace1789 it is just (codemirror. ...), so just the :as alias you used. no js/.

Artem Bezlyubchenko15:08:20

May anyone help with the macros , please? I want to have a macros - wrapper on js/require , so I can’t have myrequire.clj and use it in myrequire.cljs . And if I put defmacro in myrequire.cljs - compiler can’t find it on classpath

Artem Bezlyubchenko15:08:07

Yeah, I read it, but it defines foo in .clj, but I need a js/require ..


what does that have to do with anything? you can't actually call js/require in the macro? you can emit it only

Artem Bezlyubchenko19:08:55

yeah, I was able, my bad. Problem is in try/catch there… I want to have js try/catch there..

Artem Bezlyubchenko21:08:52

in case anyone needs: loader.clj: (ns static-assets.loader) (defmacro load-asset [path] (try` (js/require (str ~path)) (catch js/Object e# nil))) loader.cljs: (ns static-assets.loader (:require-macros [static-assets.loader])) usage: (:require [static-assets.loader :refer [load-asset]] (load-asset "./assets/ic.png")


What's the best way to truncate a string in Clojurescript? Easy would be (apply str (take my-limit s)), but this feels wasteful


(subs s 0 my-limit)


That needs safety-checks, unfortunately, since it breaks if my-limit is greater than string.length


Just wondering if those checks are teh best way to go, or if there's a better built-in somewhere

Alex Miller (Clojure team)19:08:37

not in core that I'm aware of


I don’t think it breaks in cljs land, it definitely does in clj (jvm) land

λustin f(n)19:08:25

Does anyone here have any libraries or tips on doing web client only p2p projects in clojurescript? I see there are some options in the javascript space for this (, but want to see if there are any clojurescript oriented options available before reaching for interop.

Sam Ritchie20:08:12

Hey all! I'm looking for an equals method that does what Clojurescript's does... but can compare js/BigInt , number, goog.math.Long and goog.math.Integer

Sam Ritchie20:08:45

soft equality == will work between js/BigInt and js/Number,

Sam Ritchie20:08:33

I can extend IEquiv, but that will only take if the first argument is a type other than js/Number

Sam Ritchie20:08:05

one way to do this would be to re-extend IEquiv to number to override the default behavior. Is this very-not-recommended?