This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-07-07
Channels
- # aleph (10)
- # announcements (6)
- # architecture (23)
- # atom-editor (2)
- # beginners (35)
- # biff (5)
- # cljdoc (22)
- # clojure (14)
- # clojure-europe (18)
- # clojure-hungary (26)
- # clojure-nl (6)
- # clojure-uk (6)
- # clojurescript (39)
- # core-async (1)
- # data-science (14)
- # datascript (20)
- # datomic (4)
- # graalvm (18)
- # jobs-discuss (5)
- # keechma (1)
- # leiningen (4)
- # malli (3)
- # nbb (11)
- # nextjournal (2)
- # off-topic (1)
- # parinfer (1)
- # releases (1)
- # remote-jobs (3)
- # shadow-cljs (7)
- # sql (2)
- # xtdb (4)
In https://cljdoc.org/d/funcool/promesa/8.0.450/doc/user-guide says "If the do contains more than one expression, each expression will be treated as a promise expression and will be executed sequentially, each awaiting the resolution of the prior expression"
So why this code return step 1, step 2, blocking
instead of step1, blocking, step2
(promesa/do
(promesa/resolved (js/console.log "step 1"))
(promesa/resolved (js/setTimeout #(js/console.log "blocking") 1000))
(promesa/resolved (js/console.log "step 2")))
I know js/console.log won't return a value here, but https://stackoverflow.com/a/55698897/3737707 says its okay to call resolve()
in js. So I think it is fine to write the above code?Can I use (promesa/resolved (js/setTimeout #(js/console.log "blocking") 1000))
to create a promise? So I have three promises and each execute one by one.
its not clear to me why you would. I don't use promesa so I'm not sure about its API, but it does have a timeout
function. maybe that can help with what you are trying to do?
https://cljdoc.org/d/funcool/promesa/8.0.450/api/promesa.core#resolved says it can return a promise. So my intention is that wrap a function inside resolved
so that I can create a promise here. Didn't know whether this is an anti-pattern or not.:rolling_on_the_floor_laughing:
My real use case is this:
The purpose is that I want to focus and move to the end of an editor.
But I don't want to confuse others so I use the above example to ask whether it's reasonable to wrap functions inside promesa/resolved
to create promises.
(promesa/do
(promesa/resolved (sr/ReactEditor.focus editor))
(promesa/resolved (sl/Transforms.select editor
(sl/Editor.end editor #js []))))
I don't see the point of that? I mean resolved
just gives you the result of those function call return values wrapped in a promise
If I just use this code:
(defn [editor]
(sr/ReactEditor.focus editor)
(sl/Transforms.select editor
(sl/Editor.end editor #js [])))
I can only focus in the front of the editor but not move to the end of the editor.
But execute the two functions one by one in the repl can achieve that.(defn focus-and-move-to-end [editor]
(-> (sr/ReactEditor.focus editor)
(.then (fn []
(sl/Transforms.select editor
(sl/Editor.end editor #js []))))))
Is it reasonable to say if two function A B that cannot execute on by one, then A is a promise. TBH, I only recently learn the concept of promise. And the doc here https://docs.slatejs.org/libraries/slate-react#focus-editor-reacteditor didn't mention it will return promises.
it might also be a timing issue. when you use the REPL the editor/page might be in a different state
My tests are all in the REPL now:
The first one in the repl is using defn to execute two function all at once.
The second one is (sr/ReactEditor.focus editor)
then (sl/Transforms.select editor (sl/Editor.end editor #js []))
also in the REPL.
For other people discovering this thread: I finally solved this by using short delay with promesa:
(promesa/do
(promesa/resolved (sr/ReactEditor.focus editor))
(promesa/resolved (promesa/delay 100))
(promesa/resolved (sl/Transforms.select editor
(sl/Editor.end editor #js []))))
Hi, it looks like every front-end lib is an "wrapper" around react, just wondering if is there any other solution - pure cljs ?
https://github.com/cjohansen/dumdom is a wrapper around snabbdom, with the intention of eventually getting rid of it. It is not a framework though, it is a rendering library: Components with no local state.
What are you looking to do? An app? A marketing site? A blog?
https://clojureverse.org/t/shadow-grove-a-cljs-native-solution-for-browser-based-web-frontends/9099 this could be interesting for you
is there any example for making a cljs aws lambda using shadow-cljs?
a simple one
That article was very informative when I tried writing AWS lambda functions with ClojureScript, but I found that it didn't work correctly when including other libraries that were not the AWS SDK. The code would work fine locally but the external dependencies wouldn't load when deployed to AWS lambda. I wrote a follow up post about this and other issues I came across here: https://blog.cesarolea.com/posts/aws-lambdas-with-clojurescript/ maybe it can help someone.
note that you can post-process the shadow-cljs output with https://github.com/vercel/ncc to include all the dependencies so you don't have to package node_modules
shadow-cljs can also do that but ncc has a few more features that shadow-cljs doesn't in that regard
dunno why you'd bring lein-cljsbuild into the mix? especially since you are just basically manually recreating what :target :node-library
already does?
Mainly out of familiarity, just that. Thanks for pointing out ncc! I'll definitely have a look.