This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-10-04
Channels
- # babashka (17)
- # beginners (82)
- # calva (42)
- # clj-commons (9)
- # cljdoc (2)
- # cljsrn (3)
- # clojure (142)
- # clojure-europe (12)
- # clojure-nl (1)
- # clojure-sg (1)
- # clojure-uk (14)
- # clojurescript (22)
- # community-development (3)
- # cryogen (12)
- # cursive (15)
- # data-science (13)
- # datomic (11)
- # deps-new (8)
- # emacs (3)
- # fulcro (31)
- # gratitude (7)
- # holy-lambda (8)
- # honeysql (6)
- # introduce-yourself (1)
- # jackdaw (11)
- # jobs-discuss (7)
- # kaocha (1)
- # malli (8)
- # other-languages (9)
- # pathom (14)
- # pedestal (1)
- # polylith (3)
- # portal (12)
- # re-frame (3)
- # react (3)
- # reagent (4)
- # releases (3)
- # reveal (7)
- # ring (11)
- # shadow-cljs (17)
- # specter (3)
- # sql (1)
- # timbre (2)
- # tools-deps (122)
- # xtdb (18)
ℹ️ If you use https://github.com/clojure-emacs/clj-suitable/ i.e. CIDER's clojurescript autocompletion, you can use its new bugfix release - first one in a while!
You can grab it by simply using https://github.com/clojure-emacs/cider latest (per MELPA snapshots) - it will pull cider-nrepl latest, and clj-suitable latest with it.
In particular, now completions won't choke on "string requires". Let us know how it works for you
I’m trying to translate this:
useMutation(
delete, {
onMutate: async (newTodo: string) => {
await queryClient.cancelQueries('todos')
...
return {
previousTodos
}
},
// If the mutation fails, use the context returned from onMutate to roll back
onError: (err, variables, context) => {
if (context?.previousTodos) {
queryClient.setQueryData < Todos > ('todos', context.previousTodos)
}
},
}
)
where onMutate is an async function that returns an object, and that object can be accessed from a normal function (onError), but I have no idea how to do it in cljs. Heres what I have so far using this for help
(defn handle-delete
[client key id]
(go
(<p! (.cancelQueries client key))
(let ...
{:previous previous-vals
:new new-vals})))
(defn handle-error
[err new-item context]
(let [previous (:previous context)]
(.setQueryData client previous)))
(useMutation
delete
#js {:onMutate #(handle-delete client %)
:onError handle-error
:onSettled #(.invalidateQueries client key)})
I’ve cut out a fair bit but hopefully the important stuff is all thereThe issue is that context is a #object[cljs.core.async.impl.channels.ManyToManyChannel]
Don't use core.async
at all. Instead, use JS promises - they are the ones you want when you need to translate JS async
/`await`.
Thanks, I think I misinterpreted this https://clojurescript.org/guides/promise-interop#using-promises-with-core-async I am not familiar with either promises or core async and just assumed they were compatible
Does anyone have any clues why I can't use cljs.repl/source on the output of a higher order fn? code in thread.
(defn- gen-any-value-filter [attribute]
(fn [indexed-entity]
(let [entity (util/get-indexed-entity indexed-entity)]
(some? (get attribute entity)))
)
)
----- REPL Error while processing ---------------------------------------------
(cljs.repl/source (gen-any-value-filter :phone-number))
Encountered error when macroexpanding cljs.repl/source.
AssertionError: Assert failed: (symbol? sym)
cljs.analyzer.api/resolve (api.cljc:201)
cljs.analyzer.api/resolve (api.cljc:201)
cljs.repl/source-fn (repl.cljc:1502)
cljs.repl/source-fn (repl.cljc:1493)
... snip
Because source
is a macro that expects a symbol. It can't deal with results of higher order functions at all.
Not directly. So if you have some third-party higher order function, you're out of luck. But if you're the author of such a function, you can attach metadata that would contain the code itself. But it still won't be supported by source
- it would be something you would have to know how to use.
But what's the problem you're trying to solve? Maybe there are other ways.
Ok I think I've figured it out, I think I was having trouble using the (:key map) access method with a passed-in key? making the access call as (get :key map) worked
As a test, when I add:
org.clojure/tools.reader {:local/root "/home/leif/src/tools.reader"}
to my deps.edn
file, I start getting errors about not being able to find tools.reader
in clojurescript:
No such namespace: cljs.tools.reader, could not locate cljs/tools/reader.cljs, cljs/tools/reader.cljc, or JavaScript source providing "cljs.tools.reader" in file /home/leif/.gitlibs/libs/org.clojure/clojurescript/a35a8e3927a53f69414ed684be5dfb3af27e80d8/src/main/cljs/cljs/reader.cljs