Fork me on GitHub
#clojurescript
<
2020-11-26
>
gekkou02:11:08

is there async/await syntax in cljs? im trying to use promises but having trouble when using them with threadfirst macro

Sean H03:11:24

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.

nenadalm20:11:35

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)

lilactown03:11:51

What issues are you running into with the thread first macro?

lilactown03:11:23

CLJS does not have async/await natively, but there are some libraries that implement similar to it using macros

Calum Boal10:11:13

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 dependencies

p-himik10:11:09

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

Calum Boal10:11:45

Sorry that's default in the luminus template im using, will update to mention that

👍 3
cjsauer17:11:02

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?

cjsauer17:11:25

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?

lilactown18:11:19

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

lilactown19:11:21

Basically wrote some JS that I could include in my CLJS lib which handles the class extension

lilactown19:11:56

The downside is that this seems to require emitting ES6+ code, at least at development time

thheller19:11:18

if you arte using shadow-cljs you can have real class with real extends

thheller19:11:18

extends is is just (extends FooBar) same level of (field ...)

thheller19:11:47

this emits real JS class. got tired of working around that myself 😉

thheller19:11:26

besides field, constructor, extends it acts like deftype with protocols

thheller19:11:09

inside constructor you can call (super "foo") . must be before any field is accessed

lilactown20:11:10

Have you considered upstreaming this?

thheller20:11:03

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

lilactown20:11:17

I’d love to use it in helix, but don’t want the lib to depend on shadow-cljs

lilactown20:11:27

Suppose I could copy paste

thheller20:11:39

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.

cjsauer23:11:58

The defclass macro looks really nice, thank you for posting that

leif19:11:28

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);

thheller20:11:44

@leif *target* is a compile time constant. you are not supposed to dynamically adjust it which is why you get that error.

thheller20:11:05

it is controlled by the :target compiler setting

leif20:11:57

I see. so you can't change the target when you're evaling some code?

dpsutton20:11:23

What are you hoping to accomplish?

leif21:11:08

@dpsutton I'm trying to use eval in a webpage built with :target :bundle

leif21:11:40

Which worked in clojurescript 1.10.741, but not in 1.10.773

leif21:11:16

(Note that I don't want the eval itself to be the bundle target, I would like that to be default .)