This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-09-01
Channels
- # announcements (10)
- # aws (1)
- # babashka (19)
- # beginners (104)
- # calva (50)
- # cider (17)
- # cljs-dev (135)
- # cljsrn (56)
- # clojure (240)
- # clojure-dev (4)
- # clojure-europe (19)
- # clojure-nl (2)
- # clojure-uk (7)
- # clojurescript (22)
- # conjure (2)
- # css (1)
- # cursive (10)
- # data-science (1)
- # datomic (60)
- # emacs (2)
- # events (2)
- # exercism (1)
- # figwheel-main (3)
- # fulcro (13)
- # graalvm (5)
- # gratitude (1)
- # inf-clojure (4)
- # introduce-yourself (5)
- # jobs-discuss (21)
- # lsp (36)
- # malli (6)
- # meander (8)
- # missionary (12)
- # off-topic (14)
- # pathom (13)
- # pedestal (10)
- # polylith (42)
- # re-frame (5)
- # reagent (12)
- # reitit (3)
- # releases (8)
- # sci (10)
- # shadow-cljs (37)
- # sql (5)
- # tools-deps (6)
@borkdude with :target :esm
shadow-cljs will output actual ESM code. meaning as far as JS is concerned there is actual import * as X from "term-size";
in the code when you do (:require ["term-size" :as x])
. regular CLJS does not have such a output mode and at can only output require
. import/require acting differently is decided by the host
it may work if you use :target :bundle
and run it through webpack but directly in node require
just works different than import
Makes sense, but I’ve never been able so far to ‘require’ an ES module in NodeJS but I could try to find some tool that transforms the code somehow.
hmm yeah not sure its possible. hmm didn't they discuss allowing js/import
in commonjs code? or did that never happen? guess not https://github.com/nodejs/modules/issues/454
are you sure you don't want to switch to commonjs? esm just seems to make your life harder 😛
@thheller switching to commonjs based requires (based on createRequire) is what I did before but this disallowed using ES Modules from NPM and some libraries (like term-size
) only offer their new versions as ESM. That is the only reason I switched to ESM-based :require
again (implemented using shadow.esm
: compatibility with the wider range of libs in the node ecosystem and this works with both ES modules and CommonJS modules (at the cost of the user adding $default
to their imports).
Hi everyone,
I have an object, #object[laratelli$pages$blog_post]
, and I would like to get the blog_post
string out of it. I used cljs-bean to accomplish this with some very ugly, fragile code:
> (last (s/split (:displayName (bean (:G__1 (bean (:view (:data @match)))))) "."))
;; => "blog_post"
the match
atom is from reitit.
is there a better way to do this?you shouldn't do this at all. the name of a function shouldn't be used for anything since it'll be gone in optimized builds
got it, I will try that out. thank you @thheller!
I'm trying to use the node ws
websocket module in clojurescript, but I think I'm getting stuck with how requires work. The example in the docs is this:
import WebSocket from 'ws';
const ws = new WebSocket('');
which I've translated into this:
(ns foo.core (:require ["ws" :as node-ws]))
(def ws (new node-ws/WebSocket ""))
but I get this error:
Execution error (TypeError) at (<cljs repl>:1).
fluree.db.util.xhttp.node$module$ws.WebSocket is not a constructor
I've definitely required something, since I can see the node-ws object:
(js/Object.keys node-ws) ;;=> #js["CONNECTING" "OPEN" "CLOSING" "CLOSED" "createWebSocketStream" "Server" "Receiver" "Sender"]
When the GC clears an atom, do all watches added with add-watch
also get GCed? (Or do I have to manually ensure that remove-watch
gets called?)
This prints {:v nil}
in Clojure, so I would guess it is the same in ClojureScript:
(let [atom-watcher #(println %)
my-atom (atom "")
_ (add-watch my-atom :my-atom atom-watcher)
weak-watcher-ref (WeakReference. atom-watcher)]
(future
(Thread/sleep 50)
(System/gc)
(prn {:v (.get weak-watcher-ref)})))
@leif (which suggests you don't need to call remove-watch
)