This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-08-12
Channels
- # announcements (5)
- # babashka (1)
- # beginners (193)
- # calva (79)
- # cider (18)
- # clara (4)
- # clojure (38)
- # clojure-europe (12)
- # clojure-france (8)
- # clojure-nl (12)
- # clojure-sweden (1)
- # clojure-uk (50)
- # clojurescript (37)
- # conjure (30)
- # cursive (3)
- # data-science (2)
- # datalog (7)
- # datomic (12)
- # events (2)
- # expound (3)
- # figwheel-main (1)
- # fulcro (45)
- # graalvm (1)
- # jobs (1)
- # jobs-discuss (11)
- # luminus (1)
- # malli (5)
- # off-topic (32)
- # reagent (6)
- # reitit (32)
- # shadow-cljs (25)
- # spacemacs (2)
- # sql (22)
- # vim (6)
Ported, still have to test usage.
(deftype BatchingBuffer [items n]
cljs.core.async.impl.protocols/Buffer
(full? [this]
(>= (count @items) n))
(remove! [this]
(let [[old new] (reset-vals! items [])]
old))
(add!* [this item]
(swap! items conj item))
(close-buf! [this])
cljs.core/ICounted
(-count [this]
(if (empty? @items)
0
1)))
(defn batching-buffer [n]
(BatchingBuffer. (atom []) n))
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?
Got it working. Something to do with namespaced keys
Hi guys,
I have wrapper around require
:
(defn load [path]
(try
(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?)If I don’t use str path
, I would have Invalid module:
path`. js/require
can only process strings`
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.
I use it with Expo (ReactNative) to load images from assets…
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
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.
@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 https://stackoverflow.com/questions/38255446/clojurescript-how-to-change-codemirror-reactively-with-reagent 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/
.
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.wide https://code.thheller.com/blog/shadow-cljs/2019/10/12/clojurescript-macros.html
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
yeah, I was able, my bad. Problem is in try/catch there… I want to have js try/catch there..
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
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
not in core that I'm aware of
libs like https://github.com/expez/superstring or https://github.com/funcool/cuerdas would be good places to look
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 (http://www.freedomjs.org/), but want to see if there are any clojurescript oriented options available before reaching for interop.
Thanks
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
soft equality ==
will work between js/BigInt
and js/Number
,
I can extend IEquiv
, but that will only take if the first argument is a type other than js/Number
one way to do this would be to re-extend IEquiv
to number to override the default behavior. Is this very-not-recommended?