This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-09-03
Channels
- # babashka (12)
- # beginners (15)
- # biff (2)
- # calva (17)
- # clj-kondo (19)
- # clj-on-windows (3)
- # clj-otel (1)
- # clojure (3)
- # clojure-europe (5)
- # conjure (2)
- # graalvm (2)
- # helix (5)
- # introduce-yourself (1)
- # nbb (24)
- # off-topic (32)
- # polylith (3)
- # reitit (21)
- # releases (1)
- # reveal (3)
- # scittle (1)
- # squint (56)
- # tools-deps (4)
- # xtdb (6)
Interesting, just learned about JS Proxy and thought, hmm, could this be a way to have immutable.js play well with interop and then found this: https://www.codementor.io/@rexogbemudia/immutable-js-wrapper-utility-o3qnatjlp
(ns immer (:require ["immer$default" :as produce]))
(def v1 {:a 1})
(def v2 (produce v1 #(assoc! % :b 2)))
(prn v1 v2 (= v1 v2))
So this produces an "immutable" v2 from v1 which works with any JS API. The script yields 11kb minified/bundled with esbuild which is the best one I've seen so far. Caveat: it still doesn't implement "value equals", but it assumes a unidirectional mutation such that the newest one is always equal to itself, which is I think reasonable in a lot of use casesare you still using strings for keywords? Wondering if there's a way to preserve more of Clojure semantics with this approach.
for example a http handler request / context map where I use string keys for the original unmodified request params and keywords for the coerced values
I think making different choices just makes you work against JS which is not the idea of clavascript
there is an idea to have #map {:a 1}
which defers to js/Map
so you can have arbitrary keys. assoc
etc already work with js/Map
a default one with clojure semantics and letting folks opt into an interop map that's backed by js map?
it works only accepting strings and keywords as keys, which I think means a lot of existing clojure code will break
although porting @U34K4458X’s hn-reader from cherry to clava only took minimal effort
clavascript isn't intended as a CLJS replacement: it's intended for the new/niche use case of wanting to write JS with small bundle sizes, but with a saner UX: structural editing, some drop-in stdlib functions which are similar, etc
E.g. I could write a script in Clava and upload it to my watch which only has a few kilobytes of ram/storage
Another use case is e.g. writing Github Actions, Chrome extensions, etc. Which are usually full of interop and it's nice to have those as small as possible since sometimes load on every page load. Can't afford much there
I've found several bugs in clava which I can port back to cherry. The problems are similar in clava and cherry so I don't see why we can't have both.
Is there any way to emit a[0]? Or should I stick with (get a 0)?
Is there anyway to emit: import './popup.css';
Unfortunately this does not emit the import:
(ns local-chrome-extension.popup (:require ["./popup.css"])) (a)
emits: a();
thanks!
awesome, thank you!
Is this idiomatic?
(set! (.. (js/document.getElementById :counter) -innerHTML) initialValue)
Trying to translate: document.getElementById('counter').innerHTML = initialValue;
Note that per the website, my code actually emits:
document.getElementById("counter")["innerHTML"] = initialValue;
you could also do:
(set! (.-innerHTML (js/document.getElementById "counter")) initialValue)
but it it works, it workslooks like letfn is not implemented, is that right?