clojurescript

ClojureScript, a dialect of Clojure that compiles to JavaScript http://clojurescript.org | Currently at 1.10.879
2021-05-18T01:56:51.001600Z

Is there any way to use cljc for a test ns? I'm having problems with my require-macros form in the ns form because technically it's clojure that's compiling it when it hits the compiler switch.

2021-05-18T02:16:48.001900Z

I see there are some libraries that manage to do it

Jakob Durstberger 2021-05-18T07:05:36.003500Z

I am using aws-sdk specifically the dynamodb package using the scan command which returns https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/clients/client-dynamodb/interfaces/scancommandoutput.html. Does anyone know why accessing Items like this (. result -Items) would give the following compiler warning? Cannot infer target type in expression (. result -Items)

Karol Wójcik 2021-05-18T07:21:44.003800Z

You can mark result as a ^js. This should help

thheller 2021-05-18T07:33:27.004Z

how do you call the scan? do you handle the promise correctly?

Jakob Durstberger 2021-05-18T07:35:48.004200Z

This is the whole block.

(def db (DynamoDBClient. #js{:region "eu-west-2"}))
(def table-name "tableName")

(defn items []
  (-> (.send db (ScanCommand. (clj->js {:TableName table-name})))
      (.then (fn [response]
               (->> (. response -Items)
                    (map #(-> %
                              (unmarshall)
                              (js->clj :keywordize-keys true)))))
I am also slightly surprised that js->clj does not seem to convert sets? One of the items after the last line { ... :tags #object[Set [object Set]] ...}

thheller 2021-05-18T07:36:58.004400Z

you can add support for converting sets yourself. its not done by default because that requires a certain minimum language level

thheller 2021-05-18T07:37:48.004700Z

looks fine, try logging the response. the docs say Items is optional so who knows what it is 😛

Jakob Durstberger 2021-05-18T07:38:50.004900Z

The ^js got rid of the warning, so I guess that’s ok? > you can add support for converting sets yourself Do you mean at an ad-hoc basis?

thheller 2021-05-18T07:39:16.005100Z

(extend-protocol IEncodeClojure js/Set (-js->clj [js-set options] ....))

thheller 2021-05-18T07:40:15.005300Z

ah ... misread your post. thought you were getting a JS runtime error 😛

thheller 2021-05-18T07:40:29.005500Z

yes ^js tells the compiler this is a JS object and it'll not rename stuff in :advanced

Jakob Durstberger 2021-05-18T07:44:31.005700Z

> yes ^js tells the compiler this is a JS object and it’ll not rename stuff in :advanced Thank you 🙂 > (extend-protocol IEncodeClojure js/Set (-js->clj [js-set options] ....)) Ah awesome, I’ll give that a go

Endre Bakken Stovner 2021-05-18T09:28:27.005900Z

Thanks. Weird that googling "anonymous function js curly braces" returned nothing relevant

thheller 2021-05-18T09:30:34.006100Z

really not specific to anonymous function in any way

1👍
thheller 2021-05-18T09:30:43.006300Z

let {x, y} = obj; is also valid

Pepijn de Vos 2021-05-18T14:54:57.013500Z

oy there are so many ui frameworks... re-frame, hoplon, fulcro, reagent, rum, and probably more. Rum seems the most minimal, reagent gives you an atom to work with but is otherwise just a react wrapper. fulcro and re-frame seem more full stack frameworks that use react as the view layer. hoplon seems to be its own thing entirely and not as big/active. re-frame enforces using a global atom across the app, is that common practice across the ecosystem? Their reasoning makes sense, but my understanding is that components will redraw when their atom changes, so that would mean redrawing the entire app all the time? Are there any frameworks that take more of a model view update approach similar to Elm? Not sure if this works well in ClojureScript. Maybe that's just a thing you do on top of Reagent/Rum.

Mateusz Mazurczak 2021-05-21T09:24:41.122800Z

Fulcro has similar approach, although it has high entry treshold so you will need to spend some time grasping the concepts. It is worth the time in my opinion. Also here on slack is #fulcro channel, https://fulcro-community.github.io/guides/tutorial-minimalist-fulcro/ and the author of fulcro made https://www.youtube.com/watch?v=wEjNWUMCX78&list=PLVi9lDx-4C_T7jkihlQflyqGqU4xVtsfi or https://book.fulcrologic.com/

kennytilton 2021-05-18T15:23:03.015900Z

@pepijndevos, re-frame is pretty good about minimizing refreshes if one takes care to not reference the app DB directly. ie, a subscription of a subscription will not trigger refreshes if the sourced subscription does not compute a different value when DB changes.

Pepijn de Vos 2021-05-19T09:45:56.025700Z

What do you mean with a subscription of a subscription?

kennytilton 2021-05-18T15:25:48.017500Z

As for alternatives, I am hoping to find a long weekend to get shadow-cljs to build my CLJS "React need not apply" framework. This is an intro to the JS version of that framework: https://tilton.medium.com/simplejx-aweb-un-framework-e9b59c12dcff

andrewboltachev 2021-05-18T18:25:22.017900Z

Hello. I have a figwheel-main project, which uses React (and some UI libraries) from `:foreign-libs` . When I made a copy of it (need to turn it in a similar project), in one way or another I've started receiveing an error `Uncaught TypeError: Cannot read property 'render' of undefined` with no possible way to fix. I tried to create new reagent project (`lein new figwheel-main hello-world.core -- +npm-bundle --reagent`) and take `core.cljs`file from there, but this didn't help either

phronmophobic 2021-05-18T18:48:45.018Z

> re-frame enforces using a global atom across the app, is that common practice across the ecosystem? Re-frame doesn't require or enforce a global atom, but it's the most common use case. It's a pretty common in clojurescript UI projects. > my understanding is that components will redraw when their atom changes, so that would mean redrawing the entire app all the time? Re-frame keeps track of the subscriptions used by different components so apps aren't fully rerendered (redrawing still wouldn't occur due to react and the underlying html engine) on every change. > Are there any frameworks that take more of a model view update approach similar to Elm? https://github.com/fulcrologic/fulcro has a fairly similar approach to model/view/update. My library, membrane, has an approach similar to elm, but it's focused on desktop UIs.

andrewboltachev 2021-05-18T20:31:58.018900Z

Ok, that just sounds like switching to shadow-cljs

thheller 2021-05-18T20:36:56.019400Z

that might be difficult if your code uses custom foreign-libs since shadow-cljs doesn't support those 😉

andrewboltachev 2021-05-18T21:01:02.020400Z

well that are just React and a couple of UI gadgets ("sortable" etc). so this should be good option 🙂