This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-09-25
Channels
- # aleph (15)
- # beginners (65)
- # boot (46)
- # chestnut (3)
- # cider (1)
- # clara (11)
- # cljs-dev (5)
- # cljsjs (4)
- # cljsrn (13)
- # clojure (180)
- # clojure-dev (2)
- # clojure-italy (10)
- # clojure-russia (62)
- # clojure-spec (6)
- # clojure-uk (85)
- # clojurescript (45)
- # community-development (11)
- # crypto (3)
- # cursive (10)
- # datomic (94)
- # defnpodcast (2)
- # fulcro (4)
- # heroku (1)
- # hoplon (4)
- # jobs (3)
- # juxt (10)
- # leiningen (1)
- # luminus (4)
- # mount (13)
- # music (1)
- # off-topic (10)
- # onyx (2)
- # portkey (15)
- # proton (2)
- # re-frame (16)
- # reagent (10)
- # shadow-cljs (194)
- # spacemacs (2)
- # specter (2)
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
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)})
any ideas?
@thedavidmeister Did you mean {:post [map?]}
?
um, i don't normally do it that way, didn't know i could
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 😕
is font
a restricted word for some reason? i only see this error sporadically...
@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.
Maybe you've already ensured that this is not the case
what do you mean a nil error?
That you're inadvertently passing in nil for your font value
oh, no i don't think that's the case
next time i see it i'll double check though
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
it is somewhat hard to read IMO, maybe markdown + clojure code blocks will work better?
@pesterhazy another approach for you - cats+promesa
(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))))
@yury.solovyov I agree .. haven't had time to turn it into a proper blog post yet
also wanted to get some early feedback in case I missed anything
you may consider Q/A format too, like given the problem, what the solution might look like
hmmm good idea
@mccraigmccraig interesting!! do you have a pointer to api docs?
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
so Promesa is a (thin?) wrapper around es6 promises
and cats is a funky monad abstraction on top of that?
promesa is a bluebird wrapper iirc and cats is the most straightforward clj/cljs monad lib i've come across 😁
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
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
is the thingy created by (p/promise)
a regular JS promise? I.e. is there interop with other promise-producing JS code?
yes @pesterhazy https://github.com/funcool/promesa/blob/master/src/promesa/impl.cljc#L47
that's pretty cool
the cats monad stuff is going above my head a bit (is that level of abstraction really needed here?)
I'm careful with introducing deps that I don't understand the implementation of, at least in principle
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
very interesting - seems like a great alternative to core.async (in cljs)
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)
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
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
here is a core.async example: https://gist.github.com/darwin/a667a13cd30eec5cafa4e695bd00cc79
@darwin thanks for that!
in your opinion, how does the core.async solution stack up to the alternatives?
@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.
@pesterhazy test2 hurts my head the least 🙂