Fork me on GitHub
#clojure-uk
<
2021-02-05
>
dharrigan07:02:47

Good Morning!

mccraigmccraig08:02:04

@folcon i don't like core.async for promise-like things - it's fine for streams. promesa is a good library - we've been using it concert with funcool/cats for promise stuff for ages

mccraigmccraig08:02:59

for one thing, error/exception handling is much more straightforward with promises than with core.async promise chans

folcon08:02:56

Is there any good examples on using it? I've not worked with promises much. For context, I'm using it in a function within a re-frame app, I was initially hoping to just have it resolve within a function call, ie it returns to the caller, but it seems like I have to wait for the promise to resolve and use a callback, so for the moment I've had to add in a new re-frame event handler to act as a point to receive the callback from the core async channel. It's annoyingly made the logic there a lot more complicated 😞...

mccraigmccraig08:02:15

you would have the same issue with a core.async chan - API requests always have to be decomposed into an HTTP fx and a response-handling event

mccraigmccraig08:02:08

the way we deal with it is to have a generic API fx wich takes both a success event-template and an error event-template

mccraigmccraig08:02:51

then the promise handler or core.async take op handler either conj's the success value to the success event-template, or the error value to the error event-template and dispatches that

mccraigmccraig08:02:44

something like

{:api {:GET ""
       :success [:rx-thing]
       :error [:fail-thing]}}

folcon09:02:06

Ok, good to know, I suppose I'll have to rethink that API then 😃...

mccraigmccraig09:02:09

whether you use core.async or promises, it's all just gloss over callbacks... that's the js life 😃

mccraigmccraig15:02:35

anyone have a nice way of preventing multimethod impls being removed from namespace :require decls by cljr-clean-ns ? i'm currently putting a def into the requiring namespace with a bunch of refs to vars in the impl namespaces, but it looks weird

rickmoynihan16:02:29

@mccraigmccraig: I used to put (require 'foo.ns) forms beneath the ns declaration as a convention to avoid this; when I was including a namespace for a side effect. However I now follow the convention of putting a (:require [foo.ns]) form into the ns form itself… i.e. no :refer :as etc. Some newer tooling, like clj-kondo etc knows to interpret this style of require as one to leave alone, for side effects like multimethods protocol extensions etc… Can’t recall if cljr-clean-ns has been updated or not to handle it though.

mccraigmccraig16:02:04

cljr-clean-ns does still remove the apparently unused requires... i didn't know that clj-kondo didn't annotate an ns form with no :as though - that's nice

rickmoynihan16:02:56

Yeah there was a big debate on how to handle it a few years ago here: https://github.com/clj-kondo/clj-kondo/issues/241 I think the above is the best convention for handling it.

rickmoynihan16:02:37

iirc quite a few tooling authors agreed on it too

mccraigmccraig16:02:57

huh, so they all agreed on missing :refer or :as meaning it's side effecting - but that behaviour hasn't made it as far as refactor-nrepl, at least not in v2.5.0

rickmoynihan09:02:33

Yeah it’s not updated very frequently… Might be worth adding an issue for it, I suspect it would be a pretty simple patch to this function: https://github.com/clojure-emacs/refactor-nrepl/blob/dbafd6e686402dc020d7026e21ee556812fc51da/src/refactor_nrepl/ns/prune_dependencies.clj#L118-L122

folcon18:02:44

I've got an odd issue happening at the moment, perhaps someone has seen it before? I'm using figwheel through webpack and the source-code generated has got mangled names, but when I breakpoint in the debugger, the names provided aren't mangled at all. Any ideas what could be happening? The best I've got is that for some reason some of the code is being mangled, but not others and I have no idea why... I'm currently using lots of js-invoke to keep the names unmangled, but it's not exactly the best... Anyone else seen inconsistent behavior from minification?