This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-11-26
Channels
- # announcements (3)
- # babashka (28)
- # beginners (21)
- # cider (29)
- # clojars (10)
- # clojure (14)
- # clojure-australia (3)
- # clojure-europe (48)
- # clojure-nl (3)
- # clojure-sanfrancisco (4)
- # clojure-uk (54)
- # clojurescript (34)
- # cryogen (12)
- # cursive (7)
- # datomic (14)
- # devcards (1)
- # fulcro (23)
- # helix (2)
- # java (5)
- # jobs (1)
- # kaocha (15)
- # malli (13)
- # minimallist (1)
- # off-topic (8)
- # pathom (7)
- # pedestal (1)
- # rdf (10)
- # reagent (18)
- # shadow-cljs (58)
- # spacemacs (3)
- # tools-deps (1)
- # vim (6)
- # xtdb (37)
is there async/await syntax in cljs? im trying to use promises but having trouble when using them with threadfirst macro
You can use cljs.core.async.interop/<p!
to turn a promise into a value within a go
block, at which point you can use the normal core.async
tools.
there is also official guide on promises here: https://clojurescript.org/guides/promise-interop + some libraries like promesa: https://funcool.github.io/promesa/latest/user-guide.html (I never tried any promise library)
CLJS does not have async/await natively, but there are some libraries that implement similar to it using macros
Can anyone point me in the direction of the best way to handle client side redirects using reframe with reitit front end with luminus? I've been trying this:
(rf/reg-event-fx
:redirect
(fn [_ [_ path]]
(set! (.-hash js/window.location) path)))
But i get the error:
No protocol method IMap.-dissoc defined for type string: /
Is there a more idiomatic way of handling this?
EDIT: For reference of anyone searching this slack history for a similar issue, i found this to be the solution when using the default luminus template for re-frame, where the :common/navigate
event comes from:
(rf/reg-event-fx
:redirect
(fn [_ [_ route-name]]
(let [route (reitit/match-by-name router route-name)]
{:dispatch [:common/navigate route]})))
With the event going on the same ns as the router to avoid circular dependenciesReitit should have a function for that.
Don't call side-effecting functions (like set!
) in re-frame event handlers. Use effects for that.
Your solution is not really a solution without the definition of the :common/navigate
event because it's the one that does all the work.
Sorry that's default in the luminus template im using, will update to mention that
I need to interop with a JS lib that makes heavy use of class
and extend
. Are there any libs/strategies that make this seamless in cljs? Anything I should watch out for?
The library’s primary means of extension is by subclassing the major classes. I should be able to get away with using Object.assign
from cljs perhaps?
This is a bit tricky, actually. There are some ways to “fake” it but “class ... extends ...” actually does some special things at runtime in modern browsers
Here’s what I did in a lib I maintain https://github.com/lilactown/helix/blob/master/src/helix/impl/classes.js
Basically wrote some JS that I could include in my CLJS lib which handles the class extension
The downside is that this seems to require emitting ES6+ code, at least at development time
example use here https://github.com/thheller/shadow-experiments/blob/master/src/main/shadow/experiments/grove/components.cljs#L151
inside constructor
you can call (super "foo")
. must be before any field is accessed
well technically it could just be a library since it doesn't use anything shadow-cljs specific. just to lazy to make a lib for one ns/macro
feel free to copy for now. I have a bunch of other stuff I eventually want to make standalone and not part of shadow-cljs so one day I'll definitely do it. just low priority for now.
So, is there any good way to change the *target*
value in your code?
When I try doing:
(binding [*target* "default"]
...)
In my code, it works fine unless I do :optimizations :advanced
, in which case I get the error:
SEVERE: /home/leif/src/interactive-syntax/target/public/cljs-out/prod/interactive_syntax/core.js:66: ERROR - [JSC_INVALID_DEFINE_INIT_ERROR] illegal initialization of @define variable cljs.core._STAR_target_STAR_
}finally {(cljs.core._STAR_target_STAR_ = _STAR_target_STAR__orig_val__25665);