This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2024-04-09
Channels
- # announcements (4)
- # babashka (16)
- # beginners (4)
- # calva (19)
- # cider (61)
- # clj-commons (3)
- # clj-kondo (8)
- # clojure (68)
- # clojure-boston (1)
- # clojure-brasil (1)
- # clojure-europe (16)
- # clojure-hungary (2)
- # clojure-nl (1)
- # clojure-norway (39)
- # clojure-spec (2)
- # clojure-uk (4)
- # clojuredesign-podcast (16)
- # clojurescript (17)
- # core-typed (7)
- # cursive (17)
- # data-science (7)
- # datalevin (19)
- # datomic (1)
- # events (6)
- # hyperfiddle (6)
- # kaocha (9)
- # london-clojurians (2)
- # malli (10)
- # off-topic (1)
- # other-languages (24)
- # portal (2)
- # practicalli (19)
- # rdf (1)
- # reitit (2)
- # releases (2)
- # shadow-cljs (18)
- # testing (1)
- # xtdb (20)
- # yamlscript (4)
Can anyone give me a hint about how to convert this js async/await code to cljs + Promesa?
async function makeDefaultDocument(executionContext) {
const app = require('photoshop').app;
let myDoc = await app.createDocument({preset: "My Web Preset 1"});
}
await require('photoshop').core.executeAsModal(makeDefaultDocument);
With some help from Claude llm… This works for regular promise style.
(defn make-default-document [_ opts]
(-> app
(.createDocument opts)
(p/then
(fn [my-doc]
my-doc))))
(-> core
(.executeAsModal
(fn [execution-context]
(make-default-document
execution-context
#js {:name "my new document"})))
(p/then
#(println "Document creation completed."))
(p/catch
#(println "An error occurred:" %)))
Converted to use p/let
(defn make-new-document [opts]
(p/let
[my-doc (.createDocument app opts)]
my-doc))
(p/let
[new-doc
(.executeAsModal core
(fn [executionContext]
(make-new-document #js {:name "my new document"})))]
(println "Document creation completed.")
(p/catch (fn [error]
(println "An error occurred:" error))))
Not sure if it can get more sugary.if the only intent is for make-new-document
to return the doc but never actually do anything with it you can skip the p/let entirely
Thanks, does simplify
I have an “named”? js object, and js->clj
is not working on it.
https://stackoverflow.com/questions/32467299/clojurescript-convert-arbitrary-javascript-object-to-clojure-script-map#answer-51439387
These solutions seem to get at the data. But what is best practice?
I am working in Scittle, so dont necessarily have access to goog, interop libraries, etc.
Not sure why most of those properties are greyed out, dont serialize, but I can click on them in devtools with “invoke property getter” tooltip showing.
I tend to avoid converting objects like that since their primary interface are their methods... usually its easier to just use it as a normal Javascript object with regular interop. Might depend on your use-case though
Just exploring an api right now. I was trying to convert the object to clj data and pretty-print it to view in repl. Maybe not really necessary? But maybe at some point I might want to operate on that data in regular clj data structures. Sorry, currently I feel ill at ease with js-interop and the lingo.
> Maybe not really necessary?
This. :) Not everything can be converted, far from it.
Also, even for CLJ data just pretty-printing it into a REPL is a very limited experience. I'd suggest tap>
and things like Portal, Reval, REBL.
I’m in Scittle right now, so not sure if I have access to tap>
+ Portal. That would be nice.
Ok, I’ll try to stick with js interop.
Also with Scittle I don’t have access js-interop / js-bean helper libraries. Though @U2FRKM4TW If I remember right you strongly advised against using those anyway.
I might be more at ease with Squint in terms of interop, but I’m biasing towards a fully realized repl connection right now.
Ah, right.
Yeah, I'm not really a fan of any interop library.
In that case, I myself would just stick to printing things to the JS console. Mouse navigation for deeply nested data that can show rich(er) data structures is much better than a plain-text REPL.
But if you would still rather stick to a REPL, there's js-keys
that can help. You can get any static key from an object via (.-the_key obj)
and any dynamic key via (unchecked-get obj binding-with-string-key)
.
Ok will try those out. Thanks for the pointers.
> Not sure why most of those properties are greyed out https://stackoverflow.com/a/29827859/564509
Thanks! 👀