clojurescript

ClojureScript, a dialect of Clojure that compiles to JavaScript http://clojurescript.org | Currently at 1.10.879
zendevil 2021-01-28T06:40:46.146500Z

I have a flatlist component from react native like so:

[:> FlatList {:refreshControl (r/as-element [:> RefreshControl {:refreshing @(subscribe [:refreshing])
                                                                   :onRefresh #(dispatch [:load-videos])
                                                                   }])
                 :data @(subscribe [:videos])
                 :renderItem (fn [item] (r/as-element [video-comp (get (js->clj item) "item")]))
                 :keyExtractor (fn [item] (-> (get (js->clj item) "item")
                                              (get "uri")))}]
In this component I have a RefreshControl with the prop:
:refreshing @(subscribe [:refreshing])
but upon using this prop, I’m getting the error:
No protocol method IDeref.-deref defined for type undefined:
How to fix this error?

zendevil 2021-01-28T06:42:23.147Z

there was a typo in the subscription. Problem solved!

West 2021-01-28T07:20:26.147400Z

Hey guys!

👋 2
Grigory Shepelev 2021-01-28T08:43:50.148800Z

Hi. How could I dynamically load content using Reagent with clojurescript? I wanted to just do:

(:require [cljs-http.client :as http]
          [reagent.core :as reagent]
          [cljs.core.async :refer [<! go]])
...
[:div
     (go (&lt;! (http/get "<https://raw.githubusercontent.com/borkdude/sci/master/README.md>"
                       {:with-credentials? false})))]

Grigory Shepelev 2021-01-28T08:44:50.149300Z

But it given me an error:

Uncaught Error: Objects are not valid as a React child (found: object with keys {takes, dirty_takes, puts, dirty_puts, buf, closed, add_BANG_}). If you meant to render a collection of children, use an array instead

2021-01-28T09:13:49.149700Z

there's a few problems here... I'd suggest looking at an example of loading async into a reagent app... first hit on google https://github.com/Gonzih/cljs-http-reagent-learning-template

Grigory Shepelev 2021-01-28T09:34:02.150Z

Thnx. That really helped

pinealan 2021-01-28T10:20:34.152600Z

Hey guys! Not strictly a CLJS questions, but how would you do deep linking with a reagent+reitit SPA? My first thought was to use :modules to code split, but on second thought it seems over kill?

Grigory Shepelev 2021-01-28T11:32:03.152700Z

Well. Not really. Still having a problem. For some reason it renders on "compiling" only.

uosl 2021-01-28T12:46:57.153100Z

Not sure what you mean. reitit should be able to resolve the URL path fine. You just need to make sure the server serving your SPA returns the SPA's index.html for any path.

2021-01-28T13:21:42.153500Z

In my SPA I use reitit.frontend.easy/start! when I first load. You give start! a function that Reitit will call with the matching route on initial load and any time the URL changes. In my case, the function stores the matching route and my “app” component renders the appropriate page based on the route.

2021-01-28T13:34:37.153700Z

Oh, one more thing: in my app, I don’t have specific server-side routes for each page. Those routes all return the same root page, which performs the initialization above.

pinealan 2021-01-28T14:41:01.154100Z

thanks that's sounds like a good setup

West 2021-01-28T17:49:36.159500Z

So I just had an idea for a clojurescript project. I want to make a library around https://github.com/Jarzka/stylefy and/or https://github.com/noprompt/garden to wrap around https://github.com/tailwindlabs/tailwindcss. I absolutely love tailwind, but npm isn’t so nice to work with in the clojurescript ecosystem. What do you guys think? Could this be done in an easier way? I was thinking of batch converting the tailwind css file you get via its CDN into garden syntax, then calling each tailwind class using stylefy.

dpsutton 2021-01-28T17:53:16.160200Z

i only know a little bit but i think tailwind is enormous and relies on a tool to prune down only to the actually used classes? would your library be able to replicate this?

isak 2021-01-28T17:55:23.162300Z

For what it's worth, we use tailwind and don't really have any problems. Only needed to change some of the conventions to make it worth with clojure (e.g., w-1/3 -> w-1_3), and fix the pruning logic so that it works with how reagent specifies css classes. (It's like a 50-100 line npm script to expand the whitelist before pruning)

West 2021-01-28T18:00:22.166300Z

@isak Is there any documentation on this? I’m perfectly happy doing:`[:div {:class '[tw classes]}]` I think however we could do better.

isak 2021-01-28T18:05:38.169200Z

@c.westrom Hmm we're not doing anything special, just specifying CSS classes as one normally would. I don't really see the problem personally. But yea with a native clojure solution, I guess you could avoid the bloated CSS that needs to be pruned, so it would probably be a bit simpler.

dgb23 2021-01-28T18:10:05.172500Z

When you use something like garden, then you are likely building your own compositional semantics / relations between your style rules. What tailwind does is get around the limitations of CSS in another way, by giving you the ability to generate classes based on your design system (with a JSON config). So in a sense they are solving the same problem (vanilla CSS sucks for expressing complex designs) but in a different way.

rgm 2021-01-28T19:36:24.175Z

We also use tailwind and frankly embrace the purgecss part in node and have no problems on the clojurescript side. It’s just so delightfully dumb, scanning for strings in the advanced-build cljs bundle. Here’s the very minimal lib I made up: https://github.com/rgm/tailwind-hiccup

p-himik 2021-01-28T19:38:52.177500Z

FWIW, a variant of tw is already implemented in Reagent itself.

rgm 2021-01-28T19:39:01.177800Z

we have some problems on the clj side if we use server-rendered hiccup… I haven’t figured out quite how to deal with these yet. My first rough thing has been to hijack the dev clj version of the (tw ,,,) calls to just spit out these strings into a temp text file for purgecss to look at.

p-himik 2021-01-28T19:39:06.177900Z

reagent.core/class-names.

rgm 2021-01-28T19:39:09.178100Z

oh, that’s good to know.

rgm 2021-01-28T19:39:42.178300Z

I’ve been use the fn server-side too, though, and not necessarily with reagent.

p-himik 2021-01-28T19:40:15.178500Z

That's a good point.

rgm 2021-01-28T19:40:52.178700Z

(also needed a (twp ,,,) to make working with prefixes easier … it’s a tailwind thing that’s sometimes needed to avoid conflicting with existing CSS).

👍 1
rgm 2021-01-28T19:43:11.180600Z

(also re: the original poster: the trick we’ve used to make life a little easier re NPM is to have separate the cljs build from the tailwind build. Don’t mix the streams. The clojurescript builds first, then the tailwind purge happens second).

West 2021-01-28T20:29:21.181900Z

Here’s my best attempt so far. I forked a clojurescript template using shadow-cljs and tailwind. I’m just having trouble making it my own. Also I haven’t figured out dark mode yet. I got the root HTML tag to update, but I’m trying to rewrite https://tailwindcss.com/docs/dark-mode#toggling-dark-mode-manually, so I can detect OS preferences and manual preferences. https://github.com/wildwestrom/shadow-static

clyfe 2021-01-28T21:08:02.183200Z

Compiling /home/clyfe/dev/riviera/src/riviera/core.cljs to out/riviera/core.js
Unexpected error (ExceptionInfo) compiling at (REPL:1).
No such namespace: monaco-editor, could not locate monaco_editor.cljs, monaco_editor.cljc, or JavaScript source providing "monaco-editor" (Please check that namespaces with dashes use underscores in the ClojureScript file name) in file /home/clyfe/dev/riviera/src/riviera/core.cljs
I followed https://clojurescript.org/guides/webpack With monaco-editor instead react & react-dom

clyfe 2021-01-29T09:10:31.189400Z

Fixed like this: https://github.com/bhauman/figwheel-main/issues/278

clyfe 2021-01-28T21:09:24.183300Z

clyfe 2021-01-28T21:11:29.184300Z

(ns riviera.core
  (:require
   [goog.dom :as dom]
   ["monaco-editor" :as monaco]))

rgm 2021-01-28T21:48:47.184700Z

I don’t have any opinions about the clojurescript side, but I’ve tried to put together a decent simple version of the tailwind with purge side in this example: https://github.com/rgm/tailwind-hiccup/tree/master/examples/basic

rgm 2021-01-28T21:53:36.185400Z

but for a cljs stack, you might take a look at https://github.com/rgm/experiments/tree/master/template-reframe-reitit. I keep it around to have something I can quickly copy and start sketching in.

rgm 2021-01-28T21:54:06.185600Z

figwheel builds, re-frame/reagent and reitit for front-end routing.

rgm 2021-01-28T21:56:31.185800Z

I might switch it over to shadow-cljs sometime, and would probably recommend that if you’re starting fresh. There’s just no comparison on how much easier it makes using npm packages. I think the new webpack/bundle target stuff in base cljs will be interesting. But I haven’t really taken the time to grok it.

joshmiller 2021-01-28T22:17:48.186Z

Just checking: Did you npm/yarn install?