Fork me on GitHub
#clojurescript
<
2016-11-11
>
akiroz03:11:08

I tried leaving vim and I had the same problem... and somehow my eyes don't feel comfortable without vim's default color scheme which isnt avaliable anywhere else out-of-the-box... 😞

Tim04:11:13

for home-brewed code (non libraries), can you get away without writing any javascript using cljs or do you ever have to fall back to js?

akiroz04:11:27

personally I haven't had the need to fallback to JS even when writing libraries (or JS library wrappers)

pithyless09:11:14

Has anyone run into an issue with lein-doo where it would not flush correctly to stdout? I’m running lein via node and finding it hard to debug tests involving large spec maps when it refuses to print out the entire error 🙂 https://gist.github.com/pithyless/b45fe5c7d77906d30a3d490e84e1ddf3

mping13:11:04

Hi, is there a nice idiom to deal with clojurescript <> javascript and promises?

anmonteiro13:11:46

@mping I normally use core.async, though it might be an overkill depending on your use case

mping13:11:22

@anmonteiro I’m dealing with a js lib that returns promises, I want to map it to cljs standard idiom

mping13:11:33

dont mind learning core.async if thats’ the norm

anmonteiro13:11:13

@mping right maybe I should have detailed my answer a little bit more. Here's an example to get you started:

(let [ch (cljs.core.async/chan)]
  (-> (fn-that-returns-a-promise)
    (.then (fn [result] (cljs.core.async/put! ch result))))
  ch)

anmonteiro13:11:53

if you return that ch from a function, you can then take from it somewhere else

mping13:11:01

ok I do it by hand then 🙂 I thought there was a wrap-promise-to-chan thing although that shouldnt be hard

anmonteiro13:11:37

(go (let [my-result (<! (fn-that-returns-a-channel))]
  ;; do stuff with my-result
))

joshkh13:11:06

@mping i haven't tried this library, but perhaps it could help? https://github.com/jamesmacaulay/cljs-promises

anmonteiro13:11:20

go is cljs.core.async.macros/go, and <! is cljs.core.async/<!

mping13:11:31

thanks alot, will take a look!

joshkh13:11:33

it's basically doing exactly what anmonteiro suggested by wrapping the js/* functions with core async

mping14:11:00

how do you deal with exceptions/failure of promise? sorry, never used core.async

joshkh14:11:25

if you're working directly with js interop you can handle errors like this:

(-> (js/my.Constructor. (clj->js params))
    (.promFunc1 (clj->js some-other-params))
    (.then (fn [q]
             (.log js/console "success" q))
           (fn [error]
             (.log js/console "fail" error))))

jamesmacaulay14:11:05

Hi 👋 the cljs-promises readme example shows the use of the included <? macro, which raises an exception if the promise resolves to an error

joshkh14:11:44

... did we somehow summon you? 😉

jamesmacaulay14:11:17

Haha yeah I slack notified me from the GitHub URL :face_with_rolling_eyes:

jamesmacaulay14:11:27

FWIW, cljs-promises works a bit differently from what @anmonteiro suggested

jamesmacaulay14:11:42

cljs-promises extends js Promises with the core.async ReadPort protocol

jamesmacaulay14:11:19

so you use the promise directly as a channel, and when you do so you can repeatedly read from it and get the same resolved value/error repeatedly

jamesmacaulay14:11:57

in the earlier suggestion here, it created a channel that – I believe – only gives you the value once

joshkh14:11:08

oh oops, my apologies. i gave it a really quick look. out of curiosity, is core.async's promise-chan somehow relatable to promises in cljs?

jamesmacaulay14:11:22

part of the motivation for cljs-promises was wanting to take advantage of how you can share promises between different parts of code and the different consumers can not care

jamesmacaulay14:11:30

yeah I was going to mention promise-chan

jamesmacaulay14:11:40

it came out after I wrote that library

jamesmacaulay14:11:57

from what I remember it has very similar semantics

joshkh14:11:21

i've never seen it implemented (or for that matter even mentioned on the internet)

jamesmacaulay14:11:49

never seen promise-chan implemented? like, never seen it used in practice?

jamesmacaulay14:11:29

while promise-chan has similar semantics to js Promises, in cljs they don't have any special relationship

jamesmacaulay14:11:51

I think a promise-chan would be the most appropriate thing to return from e.g. an HTTP request function in clj/cljs

jamesmacaulay14:11:27

but I guess maybe it never really caught on

joshkh14:11:04

i'm confused how a promise-chan differs from a standard chan. isn't (go (<! http-request the same thing?

jamesmacaulay14:11:35

biggest difference isn't really made clear in the documentation

jamesmacaulay14:11:30

which is that multiple consumers can repeatedly take the value of a promise-chan for as long as they want (until someone closes the promise-chan)

jamesmacaulay14:11:58

whereas with a regular chan, someone would put a value on once and then only one other consumer could get that value, once

jamesmacaulay14:11:19

the other difference is that once someone puts one value into a promise-chan, no other values can be put into it

jamesmacaulay14:11:42

this has better explanation of details than the docstring: http://dev.clojure.org/jira/browse/ASYNC-103

dnolen14:11:36

promise-chan is useful for avoiding race conditions

dnolen14:11:00

you may have independent code that all need to wait on some value but may subscribe at different times

dnolen14:11:18

you don’t want a single read to empty that channel

mping15:11:30

@jamesmacaulay how do I install the thing? didnt find any link to clojars..

jamesmacaulay15:11:48

Dependencies are definitely out of date, haven't touched it in a long time

mping15:11:49

easy enough 🙂

jamesmacaulay15:11:07

If you have any trouble let me know

idiomancy15:11:07

so my running

boot cljs
seems to do nothing. it does not really seem to generate anything

idiomancy15:11:14

i dont understand how to make js files from clojurescript files.

idiomancy15:11:26

I changed my boot version to 2.5.5 (the version in modern-cljs) and set BOOT_EMIT_TARGET to no

idiomancy15:11:30

and now it works.

hlolli15:11:37

I guess you need to do boot compile taskname, my memory may be forgetful, but with lein you can do lein cljsbuild once.

hlolli15:11:50

ok, just make sure you are not using boot cljs development build I would guess some websocket juice is added that you dont want in production.

idiomancy15:11:58

huh, interesting.

idiomancy15:11:24

I dont even have enough mental scaffolding to be properly cautious of that problem yet.

idiomancy15:11:34

Everything is just a bunch of levers without labels

idiomancy15:11:50

I'm pulling them in various sequences and hoping things happen

hlolli15:11:47

Are you looking to develop clojurescript project or do you have something ready that you want to build and deploy?

hlolli16:11:18

If you are developing with boot, in contrary to leiningen/figwheel, you don't want to see the directory with the js files, but have boot do it all automatically for you, to get auto reload everytime you save the .cljs file etc.

idiomancy16:11:57

huh, interesting, i uh.

idiomancy16:11:10

I hope this tutorial series im using addresses that?

idiomancy16:11:14

because if not im sunk?

idiomancy16:11:50

it definitely had me manually disable the warning that not emitting to a directory is deprecated

idiomancy16:11:55

@magomimmo should I have faith that the tutorial is on the same page? Are we working towards file watching here? Is building to a target directory just step one of the master plan to teach me?

idiomancy16:11:28

gosh. pretty much everything in this tutorial from a to zed is just broken on first pass. I think the first couple tutorials need to be deprecated in modern-cljs

hlolli16:11:05

ok, what's your setup now, are you running emacs?

idiomancy16:11:32

cursive. I just ran

boot serve -d target

hlolli16:11:30

ok, to be expected, depending on you setting. Make a tast in your build.boot with deftask. Last time I used boot (and this discussion may belong in #boot) this worked for me

(require
 '[adzerk.boot-cljs      :refer [cljs]]
 '[adzerk.boot-cljs-repl :refer [cljs-repl start-repl]]
 '[adzerk.boot-reload    :refer [reload]]
 '[pandeiro.boot-http    :refer [serve]])

(deftask run []
  (comp (serve)
        (watch)
        (cljs-repl)
        (reload)
        (cljs)))
(deftask development []
  (task-options! cljs {:optimizations :none :source-map true}
                 reload {:on-jsload 'lambdawerk.app/init})
  identity)


(deftask dev
  "Simple alias to run application in development mode"
  []
  (comp (development)
        (run)))
then start boot with boot repl dev

idiomancy16:11:16

hahaha, is there a quickstart quide you used? the problem is im working through a tutorial, and if I use that, I've kind of diverged from the process theyre showing me, at which point following the tutorial becomes of dubious value

idiomancy16:11:43

I dont want you to have to keep holding my hand

hlolli16:11:29

never did this tutorial, I guess they are showing you different ways of developing and serving files. Look at some boot tutorials on github, should be more updated and skip the boot part in modern-cljs.

idiomancy16:11:19

gotcha, will do!

hlolli16:11:03

and maybe start with a terminal before using Cursive, then you know after getting control of the terminal how you want to configure Cursive (calling specific boot tasks etc). I know in cider this can be pain when you need to customize variables.

magomimmo17:11:20

@idiomancy sorry to be late. May I suggest to submit an issue to modern-cljs? what's the issue you're dealing with? Take innto account that the seires has been written against boot 2.5.5.

idiomancy17:11:28

yeah, had 2.5.5 specified in the boot.properties

idiomancy17:11:51

in this latest case its the boot serve situation

idiomancy17:11:03

doesn't seem to actually serve

idiomancy17:11:39

I cant link you to specific spots in the slack thread, can I?

magomimmo17:11:03

@idiomancy any sigle tutorial has a branch. have you test them as follows? git checkout se-tutorial-01 or git checkout se-tutorial-2

idiomancy17:11:05

my 3 messages starting at 11:20

idiomancy17:11:02

No, youre right, let me try running from the premade stuff.

magomimmo17:11:14

@idiomancy I''be back at my night time (in 5 hours or more) hopefully the branch should work...

idiomancy17:11:54

okay, thanks for checking in!

pandeiro17:11:49

How could one make additional dependencies available in the Lumo REPL? I thought of just changing its build.boot to include them and re-building; is there another way?

anmonteiro17:11:40

@pandeiro ideally you don't want to build a Lumo yourself 🙂

anmonteiro17:11:07

$ lumo -c /path/to/jar
cljs.user=> (require '[your.jar :as your.jar])

anmonteiro17:11:25

check out lumo -h for all available command line options

pandeiro17:11:53

@anmonteiro It would probably take me longer to figure out the classpath to the jars I want than to add specs to build.boot and recompile 😉

pandeiro17:11:09

Or probably not, if this is compiling Node.js itself

anmonteiro17:11:21

yeah it is compiling node 🙂

anmonteiro17:11:35

lumo -c `boot show -d`

pandeiro17:11:36

But my point is I would love to have a higher abstraction - like we're spoiled with, w/ boot and lein

anmonteiro17:11:44

^ that works

anmonteiro17:11:57

or

lumo -c `lein classpath`

pandeiro17:11:01

oh so if I had a build.boot somewhere w/ what I want?

pandeiro17:11:12

That is fantastic; thank you

pandeiro17:11:20

I'm writing an Emacs mode to use Lumo btw

anmonteiro17:11:36

that sounds awesome!

pandeiro17:11:50

Yeah very frequently want to test something out very quickly

anmonteiro17:11:57

I want to eventually add support for a socket REPL, so that it can be used out of the box with inf-clojure or something

anmonteiro17:11:35

btw you can also: boot show -d > classpath.txt and

lumo -c `cat classpath.txt`

anmonteiro17:11:47

^ this way you only incur in Boot's startup time once

pandeiro17:11:00

Yes, great idea!

pandeiro17:11:12

Thank you for the help and the great tool

anmonteiro17:11:26

anything that produces a colon separated string of paths can be passed to -c or --classpath

anmonteiro17:11:31

(they're synonyms)

anmonteiro17:11:45

@pandeiro sorry it's boot show -c, not -d

pandeiro17:11:01

Yep, just figured it out here too 🙂

pandeiro17:11:24

BTW one more question: what does the 'cache' in the -k / -K args refer to?

pandeiro17:11:38

Is that a cache of compiled JS or ?

anmonteiro17:11:28

it's something to speed up requireing namespaces

anmonteiro17:11:57

sometimes self-hosted ClojureScript takes a while to compile (it's like 1.5x slower than the JVM or something like that)

anmonteiro18:11:33

so if you start subsequent Lumo sessions with -k or -K the second time it just uses the cached compiled JS

pandeiro18:11:45

ok so am I correct that in most cases, -K should just be enabled?

anmonteiro18:11:49

btw all of these options are purposely the same as Planck

anmonteiro18:11:07

(to ease the learning curve)

anmonteiro18:11:21

while I don't get a documentation website online, this should help for the most part: http://planck-repl.org/

anmonteiro18:11:49

yeah, it's useful for -K to be enabled in most cases

anmonteiro18:11:12

except for the namespaces you're actively developing, as it may mask some warnings and errors

anmonteiro18:11:25

(as it effectively skips compiling your source)

pandeiro18:11:17

Makes sense, thanks. Most of what I want with this is something very fast for quick explorations, so I think I will set -K by default

josh_tackett21:11:13

Anyone know what I’m doing wrong here?

function removeProperty(obj, prop) {
  if ( obj.hasOwnProperty(prop) ){
    delete obj.prop;
    return true;
  } else {
    return false;
  }}
justtrying to remove the prop if its there and return true otherwise false

darwin21:11:17

should be delete obj[prop]

darwin21:11:40

assuming prop is a string name of the property you want to remove

josh_tackett21:11:53

perfect thank you

practicalli-johnny22:11:48

Anyone suggest a good first tutorial or detailed guide to building your first Clojurescript app? I have seen many interesting tutorials but many seem to be out of date or require other knowledge (react, javascript, etc). I am looking for something that a group of us with basic Clojure experience can understand and successfully build something.

magomimmo22:11:40

@idiomancy I just tried the first two modern-cljs tutorials by checking out their branches (i.e. git checkout se-tutorial-01 and git checkout se-tutorial-02) mentioned by you and they work as expected.

idiomancy22:11:48

hey, I'm so sorry @magomimmo I got sidebarred by some other stuff and havent gotten to them. That's really good to hear but I didn't want you to have to sink a bunch of time into it.

magomimmo22:11:55

@idiomancy non worry, it’s one minute test.

idiomancy22:11:09

Awesome. I'll power through that more this weekend, hopefully.