This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-11-20
Channels
- # announcements (10)
- # babashka (12)
- # beginners (30)
- # calva (15)
- # clerk (7)
- # clj-kondo (15)
- # clojure (22)
- # clojure-art (2)
- # clojure-austin (1)
- # clojure-berlin (1)
- # clojure-europe (22)
- # clojure-nl (1)
- # clojure-norway (7)
- # clojure-uk (5)
- # cursive (3)
- # hoplon (1)
- # hyperfiddle (26)
- # introduce-yourself (1)
- # jobs (1)
- # joyride (13)
- # kaocha (6)
- # lsp (5)
- # matrix (1)
- # music (1)
- # off-topic (8)
- # podcasts-discuss (1)
- # practicalli (1)
- # releases (1)
- # sci (43)
- # shadow-cljs (67)
- # squint (56)
- # tools-deps (3)
Hi. I had a look through the repo but can't work out how to use Squint to iterate over a collection of elements (let's say integers) and output a nested JSX list. Is there a simple way to do this?
This is what I have:
(defn Keyboard []
#jsx [:ul
(map (fn [i]
#jsx [:li #js {:key i} i])
(range 0 10))])
(defn App []
#jsx [:div {:id "App"}
[Keyboard]])
With this code, I'm getting a warning in the console saying: Unrecognized value. Skipped inserting — LazyIterable
.Perhaps solid could be made aware if iterable values, perhaps post an issue in their repo (if it's important to you)
You could make a JS repro like this:
import { map, inc, range, take } from 'squint-cljs/core.js';
let lazyValye = take(5, map(inc, range()))
<ul>lazyValye<ul>
in react this works (I think) but in solid it doesn't, but all of these lazy things provide a Symbol.iterator
thing which is a common abstraction for JS data structures
I just verified this example with bun + react:
import { renderToString } from "react-dom/server";
import { map, inc, range, take } from 'squint-cljs/core.js';
let lazyValue = take(5, map(inc, range()))
function Component(props) {
return (
<body>
<ul>{lazyValue}</ul>
</body>
);
}
const str = await renderToString(
<Component message="Hello from server!" />,
);
console.log(str);
Running bun foo.jsx
workssomehow I'm getting Uncaught ReferenceError: React is not defined
in the browser console when trying to do so, but this must be because it's monday
I tested in this example: https://github.com/squint-cljs/squint/blob/main/examples/solid-js/src/App.cljs
[:ul (vec (interpose " " ["Hello" "world"]))]
if you remove vec
solid-js will complainwhile with the react example this just works: https://github.com/squint-cljs/squint/blob/74a5835585973623d0b2cefb5964b328ea601db5/examples/vite-react/src/MyComponent.cljs#L11
It's weird to me that the code where the warning is generated doesn't seem to be part of Solid. I think it's somehow being pulled in from this repo: https://github.com/ryansolid/dom-expressions
I've created an issue (https://github.com/ryansolid/dom-expressions/issues/294). Will see what happens.
@borkdude I didn't want to 'pollute' the other thread so forgive me for putting this here but just wanted to say thanks for your work on Squint. I'm excited about playing around with it and Solid.
Oh, and so far in my little experiment, this seems to work well in the vite.config.js
file:
// Plugin for Squint compilation
import { exec } from 'node:child_process';
const squintPlugin = () => {
return {
name: 'vite-squint',
handleHotUpdate: ({file}) => {
if (file.endsWith('.cljs')) {
exec('npx squint ' + file);
}
}
}
}
And then I just add squintPlugin()
to the list of plugins later on in defineConfig
.nice trick. I think it could be made faster if the CLI would be exposed programmatically so you don't have to start up npx
for every file.
I just use npx squint watch
myself with:
{:paths ["src"]
:output-dir "out"}
I want to publish a package to npm regarding squint. Bikeshedding...
"squint-macros"
"@squint/macros"
"@squint-cljs/macros"
macros is the package that contains the applied-science/js-interop macros (and possibly more later)
I think 2 looks better, but 3 matches the github org @U5H74UNSF
(the squint github org was already taken, this is why I named the org squint-cljs, the project itself is called /squint in that org though)
ok, can you vote like @U04V5V0V4 did ? :-D
There's also an annoying packaged called squint
on npm that I keep installing by accident. 😅 Luckily it fails to install with a loud error.