Fork me on GitHub

ℹ️ If you use 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 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 cider

👍 1

I’m trying to translate this:

    delete, {
        onMutate: async (newTodo: string) => {
            await queryClient.cancelQueries('todos')
                return {
        // 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]
    (<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)))

 #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 there


The 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 I am not familiar with either promises or core async and just assumed they were compatible


so I basically have to use .then? There’s no way to have async/await syntax?


That is correct.


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


(cljs.repl/source (gen-any-value-filter :phone-number))


----- 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.


aha, so is there a way to see what code a generation function produces?


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.


Was mostly my own curiosity to see if the function was doing what I thought it was


Ah, then it's much easier to just go to the source file and look there. :)


I mean I would think so but it eludes me a bit


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

👍 1

You probably meant (get map :key).


yes 🙂


Is there any way I can change the tools.reader library I use with clojurescript?


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:, could not locate cljs/tools/reader.cljs, cljs/tools/reader.cljc, or JavaScript source providing "" in file /home/leif/.gitlibs/libs/org.clojure/clojurescript/a35a8e3927a53f69414ed684be5dfb3af27e80d8/src/main/cljs/cljs/reader.cljs