Fork me on GitHub
#clojurescript
<
2017-09-25
>
timgilbert00:09:15

FWIW, there’s a ticket to fix that,I guess you could vote for it or whatever: https://dev.clojure.org/jira/browse/ASYNC-119

dnolen06:09:56

there’s a patch and the patch looks fine, someone should test it and report

thedavidmeister08:09:49

Can't figure out why i'm getting the error Uncaught ReferenceError: font__$1 is not defined for the last line of this function? 😞

(defn font->css-map
 [font]
 {:post [(map? %)]}
 {:font-family (font->family-str font)})

rauh08:09:56

@thedavidmeister Did you mean {:post [map?]}?

thedavidmeister08:09:38

um, i don't normally do it that way, didn't know i could

thedavidmeister08:09:31

i'm not seeing any error from the post though, actually i'm seeing this error with elide-asserts set to true, so that might not even be relevant 😕

rauh08:09:32

Actually ignore what I said, brain fart.

thedavidmeister08:09:43

is font a restricted word for some reason? i only see this error sporadically...

reefersleep11:09:00

@thedavidmeister I would (prn "font :" font) and (prn "type of font :" (type font)) both inside your function and at your call sites before doing anything else. Your problem looks like a simple nil error to me, although with a cryptic message.

reefersleep11:09:34

Maybe you've already ensured that this is not the case

thedavidmeister11:09:56

what do you mean a nil error?

reefersleep11:09:10

That you're inadvertently passing in nil for your font value

thedavidmeister11:09:40

oh, no i don't think that's the case

thedavidmeister11:09:47

next time i see it i'll double check though

pesterhazy13:09:44

If anyone is interested in using Promises from ClojureScript, I've written a demo/walkthrough on different approaches to the problme of passing intermediate values inside a Promise chain: https://gist.github.com/pesterhazy/74dd6dc1246f47eb2b9cd48a1eafe649 -- feedback very welcome

yury.solovyov13:09:06

it is somewhat hard to read IMO, maybe markdown + clojure code blocks will work better?

mccraigmccraig13:09:13

@pesterhazy another approach for you - cats+promesa

mccraigmccraig13:09:18

(require '[cats.core :refer-macros [mlet return]])
(require '[cats.context :refer-macros [with-context]])
(require '[cats.labs.promesa :as pm])

(defn cats-promesa [n]
  (with-context pm/promise-context
    (mlet [:let [n 5]
           n-squared (return (square 5))
           result (return (+ n n-squared))]
      (prn result)
      (return result))))

pesterhazy13:09:01

@yury.solovyov I agree .. haven't had time to turn it into a proper blog post yet

pesterhazy13:09:28

also wanted to get some early feedback in case I missed anything

yury.solovyov13:09:59

you may consider Q/A format too, like given the problem, what the solution might look like

pesterhazy13:09:10

hmmm good idea

pesterhazy13:09:24

@mccraigmccraig interesting!! do you have a pointer to api docs?

mccraigmccraig13:09:20

cats doesn't have explicit docs for the promesa promise - it does have docs for the manifold/deferred promise though, and one promise monad is much the same as another - http://funcool.github.io/cats/latest/#manifold-deferred

pesterhazy13:09:03

so Promesa is a (thin?) wrapper around es6 promises

pesterhazy13:09:16

and cats is a funky monad abstraction on top of that?

mccraigmccraig13:09:35

promesa is a bluebird wrapper iirc and cats is the most straightforward clj/cljs monad lib i've come across 😁

mccraigmccraig13:09:49

it's quite easy to wrap any old promise lib up as a promise monad though, so it's easy enough to adapt the approach - here's the promesa monad context - https://github.com/funcool/cats/blob/master/src/cats/labs/promise.cljc

mccraigmccraig13:09:35

a further nice thing you can do with cats and promises is to use alet instead of mlet, which will then infer the dependencies between bindings and create an optimal promise tree - this is shown in the manifold link above, but applies equally to promesa or any other applicative

pesterhazy13:09:25

is the thingy created by (p/promise) a regular JS promise? I.e. is there interop with other promise-producing JS code?

pesterhazy13:09:51

that's pretty cool

pesterhazy13:09:54

the cats monad stuff is going above my head a bit (is that level of abstraction really needed here?)

pesterhazy13:09:23

I'm careful with introducing deps that I don't understand the implementation of, at least in principle

mccraigmccraig13:09:34

it's awesome. i have a tonne of async clj and cljs, all using cats+promesa|manifold/deferred - and the code reads very closely to the synchronous equivalents

pesterhazy13:09:36

very interesting - seems like a great alternative to core.async (in cljs)

mccraigmccraig13:09:53

what dyu mean re the level of abstraction ? you don't need to understand what's going on in the background to use mlet or alet (although using them for a while will help you understand the abstraction from my own experience)

mccraigmccraig14:09:06

re core.async, yeah, i got rid of core.async in our cljs for promise-like things, so we only use it for stream-like things now

mccraigmccraig14:09:53

although, to ice the cake, you can also use core.async channels in the same way 😬https://github.com/funcool/cats/blob/master/src/cats/labs/channel.cljc

pesterhazy14:09:57

@darwin thanks for that!

pesterhazy14:09:41

in your opinion, how does the core.async solution stack up to the alternatives?

darwin14:09:44

@pesterhazy I'm not familiar with cats, I prefer core.async because I'm pretty familiar with it. So typically I tend to convert js promises to core.async channels and back. When I need to do a lot of interop and it is not worth converting I might stay on js-promise side and use promises directly with js interop.

john18:09:56

@pesterhazy test2 hurts my head the least 🙂