Fork me on GitHub
#clojurescript
<
2021-05-18
>
Joshua Suskalo01:05:51

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.

Joshua Suskalo02:05:48

I see there are some libraries that manage to do it

Jakob Durstberger07:05:36

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ójcik07:05:44

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

thheller07:05:27

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

Jakob Durstberger07:05:48

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]] ...}

thheller07:05:58

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

thheller07:05:48

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

Jakob Durstberger07:05:50

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?

thheller07:05:16

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

thheller07:05:15

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

thheller07:05:29

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

Jakob Durstberger07:05:31

> 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

Pepijn de Vos14:05:57

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.

phronmophobic18:05:45

> 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.

Mateusz Mazurczak09:05:41

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&amp;list=PLVi9lDx-4C_T7jkihlQflyqGqU4xVtsfi or https://book.fulcrologic.com/

kennytilton15:05:03

@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 Vos09:05:56

What do you mean with a subscription of a subscription?

kennytilton17:11:31

Wow, where did this old message come from! 🤷 Sorry I missed it. Anyway, look for "Layer 3 (materialised view) subscriptions". https://day8.github.io/re-frame/subscriptions/ In the example there, the sub named :id subscribes to two other subscriptions, :a and :b 2.

(reg-sub 
  :id

  ;; signals function
  (fn [query-v] 
    [(subscribe [:a]) (subscribe [:b 2])])     ;; <-- these inputs are provided to the computation function 

  ;; computation function
  (fn [[a b] query-v]                  ;; input values supplied in a vector
      (calculate-it a b)))
Supposing those are not themselves "layer 3" subscriptions, then, when the DB changes, :a and :b will be re-computed. But if they do not come up with new values, re-frame will not recompute :id, and no subscriber of :id will re-render.

kennytilton15:05:48

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

andrewboltachev18:05:22

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

andrewboltachev20:05:58

Ok, that just sounds like switching to shadow-cljs

thheller20:05:56

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

andrewboltachev21:05:02

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