This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-08-28
Channels
- # announcements (2)
- # babashka (36)
- # beginners (29)
- # bristol-clojurians (2)
- # calva (3)
- # cider (102)
- # circleci (7)
- # clj-kondo (5)
- # cljs-dev (7)
- # clojure (117)
- # clojure-europe (23)
- # clojure-korea (1)
- # clojure-nl (1)
- # clojure-spec (15)
- # clojure-uk (47)
- # clojurescript (43)
- # code-reviews (1)
- # community-development (1)
- # conjure (32)
- # cursive (1)
- # datalog (15)
- # datomic (14)
- # emacs (18)
- # fulcro (9)
- # helix (23)
- # jackdaw (1)
- # jobs-discuss (10)
- # meander (8)
- # membrane (57)
- # off-topic (4)
- # portal (2)
- # re-frame (22)
- # reagent (1)
- # reitit (9)
- # reveal (3)
- # rewrite-clj (14)
- # shadow-cljs (22)
- # spacemacs (27)
- # sql (34)
- # testing (6)
- # tools-deps (40)
- # vim (5)
- # vrac (15)
- # xtdb (2)
Hi guys, I’m having problems using the promesa
library. For example I’m trying to evaluate this small piece of code I got from the promesa user guide:
@(-> (p/resolved 1) (p/then inc))
But I’m getting:
=> #object[Error Error: No protocol method IDeref.-deref defined for type object: [object Promise]]
yeah, JS is single threaded so you cannot block to wait for something since that would never arrive
I was trying to play around with promesa because I’m having another problem with it. I have the following code:
(defn note-exists
[identifier]
(p/promise
(fn [resolve reject]
(ajax/GET (str BASEURL "/api/notes/" identifier "exists")
{:handler resolve
:error-handler reject
:response-format (ajax/ring-response-format)}))))
(defn- handle-create-note
[]
(-> (note-exists @active-note)
(p/then #(.log js/console %))
(p/catch #(.log js/console %))))
handle-create-note
is being executed on button click. However, the following is being printed:
function note_exists(resolve, reject)
It seems as if the value of the promise is the inner function and it does not execute the ajax request
I have found a solution, seems like some examples on the Internet are not up to date anymore, at least regarding cljs. I had to use (p/create ...)
instead of (p/promise ...)
. Now it works fine. Thanks!
Assume IFn
's -invoke
is implemented for js/Element
so I should be able to invoke the elem
here.
(defn mksvg [tag]
(fn [& args]
(let [[attr kids] (parse-args args)
xmlns ""
elem (.createElementNS js/document xmlns tag)]
(elem attr kids))))
But when I call this, I get TypeError: elem is not a function
. I can get around this by using apply
just wondering if this is expected behavior.in shadow-cljs this sort of breaks since it assumes JS types don't implement IFN for an optimization I did. see https://github.com/thheller/shadow-cljs/issues/742
Perhaps it could be solved by treating an ^IFn
tag in a special way? So that
(let [elem ^IFn (.createElementNS js/document xmlns tag)]
(elem attr kids))
would emit a code that uses -invoke
.nah I'll just add a flag to turn off the optimization for people that don't care 😉
^IFn elem (.createElementNS js/document xmlns tag)
might already work. this is only an issue because elem
inherits the js
tag from js/document
BTW is there any difference between (let [^IFn elem (...)])
and (let [elem ^IFn (...)])
?
I don't think ^IFn (...)
does anything but not actually sure. don't think I've ever used this variant.
so I don't forget to actually add the flag: https://github.com/thheller/shadow-cljs/issues/783
greetings! is there faster way to split vector in 2 parts, insert another vector between those, and glue those back together as a vector?
(let [r (vec (range 20000))]
(do
(time
(into
(into
(subvec r 0 10000)
[\a \b \c])
(subvec r 10000)))
nil))
"Elapsed time: 11.960002 msecs"
https://www.clojure-toolbox.com/ has some interesting options under "Data Structures". I think https://github.com/clojure/core.rrb-vector might be what you're looking for
(let [r (vec (range 20000))]
(do
(time
(into
(into
(subvec r 0 10000)
[\a \b \c])
(subvec r 10000)))
nil))
"Elapsed time: 28.849998 msecs"
=> nil
(let [r (vec (range 20000))]
(do
(time
(rrbv/catvec
(rrbv/subvec r 0 10000)
[\a \b \c]
(rrbv/subvec r 10000)))
nil))
"Elapsed time: 7.060001 msecs"
note the memory impacts too - subvecs just takes slices out of the original vector, which is retained in full
This will seem like an odd question. But whats a simple function that would result in a js error. It’s for testing a macro that does error handling.
my goto is (/ 1 0)
This is actually ininity xD
whoops. I guess I'm usually in clj
Yea I guess I just stick with the throwing. It just didn’t seem right to me for some reason.
There is some looping functions also. So the get-in
one seems like a good option for that
Do you guys know why the build watcher triggers twice each time I make a change? First time it compiles, second time it just copies some jar files witch are copied in the first step too. I have took the function from https://funcool.github.io/clojurescript-unraveled/#watch-process . Thank you :)