clojurescript

ClojureScript, a dialect of Clojure that compiles to JavaScript http://clojurescript.org | Currently at 1.10.879
gekkou 2020-11-26T02:26:08.428500Z

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

nenadalm 2020-11-26T20:43:35.450Z

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)

lilactown 2020-11-26T03:00:51.429300Z

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

lilactown 2020-11-26T03:01:23.430300Z

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

Sean H 2020-11-26T03:07:24.430400Z

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.

Calum Boal 2020-11-26T10:07:13.431400Z

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-himik 2020-11-26T10:23:09.431900Z

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 Boal 2020-11-26T10:29:45.432100Z

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

👍 1
cjsauer 2020-11-26T17:47:02.435500Z

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?

cjsauer 2020-11-26T17:48:25.436800Z

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?

lilactown 2020-11-26T18:59:19.439100Z

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

lilactown 2020-11-26T19:00:52.439700Z

Here’s what I did in a lib I maintain https://github.com/lilactown/helix/blob/master/src/helix/impl/classes.js

lilactown 2020-11-26T19:01:21.440700Z

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

lilactown 2020-11-26T19:01:56.441600Z

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

thheller 2020-11-26T19:10:18.441800Z

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

thheller 2020-11-26T19:11:18.442300Z

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

thheller 2020-11-26T19:11:47.442500Z

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

thheller 2020-11-26T19:12:26.442700Z

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

thheller 2020-11-26T19:13:09.442900Z

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

2020-11-26T19:43:28.444600Z

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

lilactown 2020-11-26T20:19:10.447100Z

Have you considered upstreaming this?

thheller 2020-11-26T20:26:03.447700Z

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

thheller 2020-11-26T20:26:44.448500Z

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

thheller 2020-11-26T20:27:05.448800Z

it is controlled by the :target compiler setting

2020-11-26T20:28:57.449500Z

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

dpsutton 2020-11-26T20:34:23.449900Z

What are you hoping to accomplish?

lilactown 2020-11-26T20:49:17.451100Z

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

lilactown 2020-11-26T20:49:27.451600Z

Suppose I could copy paste

thheller 2020-11-26T20:50:39.451800Z

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.

2020-11-26T21:20:08.452300Z

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

2020-11-26T21:20:40.452800Z

Which worked in clojurescript 1.10.741, but not in 1.10.773

2020-11-26T21:21:16.453600Z

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

cjsauer 2020-11-26T23:24:58.454800Z

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