This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-09-03
Channels
- # announcements (3)
- # beginners (114)
- # calva (42)
- # cider (90)
- # clj-kondo (3)
- # cljsrn (6)
- # clojure (40)
- # clojure-conj (4)
- # clojure-dev (3)
- # clojure-europe (4)
- # clojure-italy (3)
- # clojure-nl (4)
- # clojure-quebec (1)
- # clojure-spec (3)
- # clojure-uk (130)
- # clojurescript (31)
- # cursive (3)
- # data-science (3)
- # datavis (1)
- # datomic (5)
- # dirac (3)
- # fulcro (16)
- # jobs (1)
- # joker (6)
- # music (5)
- # off-topic (14)
- # re-frame (19)
- # remote-jobs (8)
- # shadow-cljs (37)
- # slack-help (4)
- # tools-deps (22)
- # xtdb (8)
Afaik it’s not used, as other concurrency mechanisms are present. I do recall this tho; https://mobile.twitter.com/roman01la/status/1155602189311717377
I don't see how async
and await
are semantically meaningful for Clojure. They are kind of a kludge due to JS not having macros 😛
If you like, you could write an async/await let
macro that binds a promise result to a variable and wraps the body in a then
, wouldn't be surprised if someone had written one.
Alternatively, promise sugar could be added to a threading macro like ->
For the kicks I wrote a small toy implementation
; macro
(defmacro async-let
[bindings & body]
(let [form (bindings 0)
async (bindings 1)]
`(.then ~async (fn [~form] ~@body))))
; usage
(async-let [response (js/fetch "index.html")]
(async-let [txt (.text response)]
(println txt)))
it doesn't handle errors or more than just one binding
I don’t get the point of async/await. Why is it a good idea to decide that the function is async upon declaring it, and not leave this detail to the caller?
Anyway, there’s also https://funcool.github.io/promesa/latest/, which utilizes JS promises, I believe.
> I don’t see how async
and await
are semantically meaningful for Clojure.
> I don’t get the point of async/await.
Ya’ll. srsly?
@ULZE0PA2K The answer to your question is to use core.async. It provides roughly the same semantics as async
/`await`.
> They are kind of a kludge due to JS not having macros
In a lot of (but not all) ways, core.async would be better were it tightly integrated w/ the compiler. There have been a number of compiler-level bugs that had to get rooted out of core.async.
> Why is it a good idea to decide that the function is async upon declaring it, and not leave this detail to the caller?
This is literally what go
blocks do in core.async. If you want to know why that’s useful, go watch Rich’s talk on it.
Hi guys
i have a question about interop.
I am not sure how to approach the spreading of props
DrawerItems {...props}
how do i translate this to cljs?
oki so for the context
i am trying to use https://reactnavigation.org/docs/en/3.x/drawer-navigator.html
i am creating drawer-navigator component in my re-natal app.
it works but it uses the default drawer.
I'd like to customize the drawer so i am translating this example https://medium.com/ltunes/how-to-do-hamburger-menu-in-react-native-application-200d92825988 to cljs.
Sorry if this is stupid question but how do i pass props to js component?
Do i just aset
them?
or [:> DrawerItems props]
if you already have a props map. that would match the {...props}
has anyone used material-ui with Clojurescript? I am unable to reproduce the following example from the official docs https://github.com/mui-org/material-ui/blob/master/docs/src/pages/components/dialogs/ResponsiveDialog.js#L13 and I can’t find Clojurescript examples where they use useTheme
. When I do js/MaterialUIStyles.useTheme
it returns a function, but executing that function causing
Uncaught Invariant Violation: Invalid hook call. Hooks can only be called inside of the body of a function component
any clues?I am using material-ui with reagent without issues. You can't use hooks inside reagent components: https://github.com/reagent-project/reagent/blob/master/doc/ReactFeatures.md#hooks material-ui have also some higher order components - probably from historic reasons that you can use. As for the theme, here is sort of copy pasted code from one of the apps I am working on:
;; materia-ui.core (later aliased as `ui`)
;; ns contains react components after `reagent.core/adapt-react-class`
(def ^:private create-mui-theme* (goog.object/getValueByKeys js/window "MaterialUiStyles" "createMuiTheme"))
(defn create-mui-theme [theme]
(create-mui-theme* theme))
;; app.core
(def ^:private theme
(ui/create-mui-theme
#js {:palette #js {:primary #js {:main "red"}}}))
(defn app []
[ui/ThemeProvider {:theme theme}
[current-page]])
Yeah, I didn’t see that doc until someone pointed at it. Thanks for the snippet, I’m gonna try it.
hmm. there’s something entirely else I guess, even this simple example doesn’t work:
(defn dialog []
(let [[count set-count] (js/React.useState 0)]
[:div
[:strong "<-state Hook:"]
" "
[:button {:on-click #(set-count (inc count))}
count]]))