Fork me on GitHub
#clojurescript
<
2018-06-14
>
justinlee01:06:56

Could someone sanity check something: I haven’t tried to use the promesa async macro since 1.10 came out and now I cannot get it to compile. Test file src/tst/core.cljs:

(ns tst.core
  (:require
    [promesa.core :as p]
    [promesa.async-cljs :refer-macros [async]]))

(println "hello world")
deps.edn:
{:deps {org.clojure/clojurescript {:mvn/version "1.10.238"}
        funcool/promesa {:mvn/version "1.9.0"}}}
and then invoke it as clj --main cljs.main --compile tst.core --repl. I get a No such namespace: cljs.core.async.impl.dispatch--but I know this worked in a previous version. maybe I’m just using the new command line tools incorrectly. This is my first attempt at using them.

bhauman01:06:43

@lee.justin.m do you need to require core.async?

dylandrake01:06:10

What is the best method to wrap a reagent/render to make sure the element is loaded and not get the "Target container is not a DOM element" exception? Edit: I should probably ask this in #beginners.

justinlee01:06:53

@bhauman that was it thanks! when i was doing this before I was also already using core.async so I didn’t realize it had a dependency on it

justinlee01:06:37

do transitive dependencies not work with deps.edn or does funcool/promesa just not declare one when it should?

richiardiandrea01:06:28

@lee.justin.m it seems that the dep is provided in there and I think clojure cli does not handle them, but double check in #tools-deps - https://github.com/funcool/promesa/blob/master/project.clj

richiardiandrea01:06:55

That is why you need to add it explicitly

Alex Miller (Clojure team)01:06:27

the whole point of provided is that the consumer is supposed to provide it instead

Alex Miller (Clojure team)01:06:53

it’s intentionally not a transitive dep

Alex Miller (Clojure team)01:06:22

in this case, that seems wrong

Alex Miller (Clojure team)01:06:37

there are a pretty small set of cases where provided is the right answer

tommmyy08:06:16

I would like to see more advanced guide that explains topics such as: asynchronous chunks, webpack loaders etc.

dnolen01:06:15

will be pushing out a release on Friday, you can try this out with master

👍 4
dnolen01:06:45

hopefully this dispels a lot of mystery on how foreign libs and externs inference is meant to work

bhauman02:06:19

Very cool!

dnolen02:06:48

also kind of nice succinct guide on how to use webpack for doing really basic stuff

dnolen02:06:56

I wasted 3 hours distilling this

justinlee02:06:01

very nice! maybe i don’t have to send out @pesterhazy’s double bundle link twice a week anymore 🙂

👍 4
4
dpsutton02:06:05

I wouldn't consider it wasted

4
dnolen02:06:04

well I mean just that wow - lots of old links, lots of incomplete information, lots of extra stuff, too many options, create-react-app isn’t configurable … and on and on

dnolen02:06:22

while we certainly have things to work on - I think we’re doing swell - I can’t believe that people have the patience for this stuff

justinlee02:06:52

though criticizing create-react-app for not being configurable is like criticizing a harley davidson for being loud. that’s kind of Its Thing.

😂 8
dpsutton03:06:13

back to the getting more people involved, I got involved with CIDER thanks to some "low hanging fruit" tags on issues. could easily find a template for what to do and the tickets were good introductory tickets

johnj03:06:12

so closure/cljs can infer all externs for react(after webpacking) without warnings? nice

johnj03:06:01

what's different here? https://clojurescript.org/guides/externs it emit warnings for a simple lib

Mikko Harju13:06:23

What are the caveats for property access in JS? I’m seeing a totally weird situation where printing the object as a whole in console.log prints out the object containing property to: 100 but when I access it by (.-to props) or (js* "") I get undefined…. This happens only under advanced compilation mode

Mikko Harju13:06:56

I’ve never ever come accross this kind of a situation

Mikko Harju13:06:36

I’ll try to assign it to a variable I can access from the console. let’s see.

dnolen13:06:45

that’s how advanced compilation works

dnolen13:06:57

you cannot expect the names to remain the same

Mikko Harju13:06:47

Oh… oh… I see.. 😄

Mikko Harju13:06:09

So even property getters get mungled inside a fn?

dnolen13:06:33

all static property access is subject to munging

Mikko Harju13:06:35

So the getter is not (.-to prop) but something else?

dnolen13:06:37

doesn’t matter where

Mikko Harju13:06:48

OK, this only happens with one property in the whole app

Mikko Harju14:06:00

All the other props come out cleanly

dnolen14:06:17

but you probably got lucky

dnolen14:06:31

if you’re dealing with data don’t use static property access

Mikko Harju14:06:49

OK, I’d use the goog-getters then?

dnolen14:06:53

goog.object namespaces provides useful fns

Mikko Harju14:06:55

This is so obvious now… Works like a charm, thanks @dnolen!

paytonrules14:06:50

I have a follow up question to this - should you ever really use the (.-propertyName syntax? It seems like you’re always at risk of getting munged. And if you shouldn’t - why even have the syntax?

john14:06:54

Some hosty interop stuff will not be munged, so it'll still be common

john17:06:31

Wait no, even host interop stuff can get munged...

troglotit14:06:31

Why does my (.-maps google) compiles to $update-map$.$maps$ i.e. it munges my properties? It happens in production mode using shadow-cljs. And how to make it safe to property munging if library is loaded as third party script? Solved it using ^js

Andreas Liljeqvist15:06:53

How do I deal with 2.0 getting autoconverted to 2?

Andreas Liljeqvist15:06:35

Not fun with a deep datastructure where floats become ints

Andreas Liljeqvist15:06:01

Datomic and my specs are very unhappy

troglotit15:06:38

@andreas862 Clojurescript uses Javascript numbers, so everything is a float. Maybe that’s why you see autoconversion

dnolen15:06:33

@paytonrules you should always use .- for programmatic stuff - non-data

dnolen15:06:30

getting munged isn’t a risk - it’s nearly always what you want for your program - you just don’t want it for the JS interop data bits

dnolen15:06:10

ClojureScript data structures get completely munged for example

dnolen15:06:19

and you never worry about this stuff

Andreas Liljeqvist15:06:01

@troglotit I would guess that as well. Problem is that I somehow must sanitize all data sent to the server. And I can't use the same spec for client/server

paytonrules15:06:34

Thanks for the clarification @dnolen - this is a part I get continuously tripped up by

dnolen15:06:12

@andreas862 I don’t really understand your problem

dnolen15:06:34

floating point should be encoded as ~f on the server

dnolen15:06:17

and that will be preserved on the client side

dnolen16:06:37

it may be that you always want to write floating point on the client if you have a number

dnolen16:06:21

recent releases of transit-cljs have a :transform option for the writer - you can intercept all values before they are written and do a switcheroo to accomplish this

Andreas Liljeqvist16:06:09

On the server I have {:my-floating-point 5.0}, when I round trip it through the server->client->server I get {:my-floating-point 5} back - But it might be something else like Sente/transit influencing that

athomasoriginal16:06:50

@dnolen Just read over the new blog post. Really great stuff. From my understanding, it is letting webpack handle node_moudles so that you can use the output in your project, but I think I am missing some context. When/why would I choose this option over :npm-deps? Is this to allow us to use a larger set of npm deps without having to send it through the closure compiler?

dnolen16:06:14

@andreas862 hrm actually float is ~d and I see how this could happen, so yeah it is asymmetrical - but I still think you should be able to find a OK way to work around this

dnolen16:06:02

@tkjone because :npm-deps has edgecases - thus lot of people use shadow-cljs for Node modules stuff - but the post is demonstrating precisely what ClojureScript supports which far as I can tell there’s an incredible amount of confusion about

dnolen16:06:40

but the problem was one of documentation - I don’t think anybody really understood how :global-exports and extern inference are supposed to interact to make this stuff painless

dnolen16:06:35

you might still want to use shadow-cljs because it’s convenient, easier - but everyone should know you can get the same results with a small amount of effort w/ ClojureScript alone

athomasoriginal16:06:24

Awesome, thats pretty much how I interpreted it. So in other words: For many libraries, we provide you with :npm-deps and that works in most cases and is being improved, but there are cases where it will not always work as expected, and when that happens you can use traditional JS tooling, like webpack, and have your project consume that...

dnolen16:06:13

@andreas862 in projects where where floating point rep mattered we just wrapped in BigDecimal since we weren’t using this for computation anyway since we didn’t want to do that on the client

Andreas Liljeqvist16:06:03

wrapped the response from the client?

dnolen16:06:05

@tkjone exactly, :npm-deps is a long term investment - but this meme that you can’t use ClojureScript easily with Node stuff needs to die

👍 16
theeternalpulse16:06:38

Does clojurescript allow metadata on functions?

theeternalpulse16:06:02

I'm trying to log out metadata that I attached on a function but (meta fn) shows null

darwin17:06:23

(meta (with-meta (fn []) {:x 42}))

darwin17:06:03

you probably didn’t attach metadata to a function, but to a var holding a reference to function

theeternalpulse17:06:58

I'm using

(defn lesson
  {:some-meta 1}
  []
  (fn []
    [:div]))

theeternalpulse17:06:18

it has to use with-meta?

darwin17:06:21

AFAIK when you set metadata via defn, it gets attached to the var created, not to the function object itself

darwin17:06:49

see (doc defn) it is explicit about it

darwin17:06:48

how do you read that metadata?

darwin17:06:01

(meta lesson) should still give you what you expect

theeternalpulse17:06:09

ok I got what you meant earlier

theeternalpulse17:06:30

I am passing the function reference, so that makes sense

darwin17:06:29

then use with-meta, it will create a wrapper of the original function, which acts as original function but also has support for meta-data protocols

👍 4
darwin17:06:03

btw. you can see the difference between result of (fn []) and (with-meta (fn []) {}) in REPL

darwin17:06:11

the second one returns #object[cljs.core.MetaFn]

Joe G20:06:15

Does anyone have experience with Medium Editor?

tungsten21:06:56

The problem with all these "look we can consume UMD modules easily" posts is that they are always toy projects that do not reflect real world usage. I will take it upon myself this weekend to document the immense difficulty/impossibility to get reagent + figwheel + a react library working using node modules. Maybe the actual clojurescript compiler can handle this, but most people are not starting at these "low levels" they are trying to make things work with leiningen, which has been a completely fruitless endeavor for most people. I'm not sure where the problem lies, I will explore the differences with lein-cljsbuild/figwheel and just using the new clj tool this weekend. And by things work I mean "reagent + react16 + a random tiny react component distributed as a UMD module. " Maybe react is a PITA, but it is the defacto standard for view rendering in cljs. If I'm delusional hopefully documenting things will bring clarity to the error in my ways.

👍 4
dnolen21:06:31

@bfast you can save yourself the trouble - people have already done it, it works

dnolen21:06:44

people have been using Webpack to bundle node_modules for years

👍 4
dnolen21:06:31

the only that has changed is you don’t have to write externs yourself, and interop looks less ugly

dnolen21:06:15

also none this has anything to do with boot / lein / clj

dnolen21:06:21

the choice of tools doesn’t matter in the slightest

dnolen21:06:43

that said - the problem is two-fold

dnolen21:06:24

A) people expect tools to magically do X, when you may have to do a couple things on your own B) tools aren’t that well documented so you can figure out A) is possible

johanatan21:06:31

everyone doing those couple of things on their own (cargo culting & in slightly different ways from one another) is obviously not a very sustainable model either though. or perhaps it is and I'm just not clued into it yet.

johanatan21:06:43

certainly everybody has their own very personalized emacs setup

dnolen21:06:03

that statement doesn’t really align with my experience

johanatan21:06:05

and perhaps the clojure tooling behind each dev's setup is no different from the emacs philosophy

dnolen21:06:16

every actual application that people are actually shipping don’t do standard things

dnolen21:06:24

it’s hodge podge of cargo-culted stuff

dnolen21:06:31

any programming language, any stack, any company

johanatan21:06:01

@dnolen perhaps true. it just seems to be a bit more pronounced in the clj/cljs community

dnolen21:06:18

all I have to say is wat? 🙂

dnolen21:06:29

it’s the same in every programming language community I’ve ever been a part of

dnolen21:06:32

JS is way worse

tungsten21:06:52

I have never found a post hammering out all the details I am talking about. Specifically reagent 0.8 + react UMD foreign lib. I hope you are right David, but I spent multiple hours yesterday trying to get it to work, so I am not convinced. I am trying to be constructive by documenting where I am getting stuck. Are you saying webpack is the only way to make this work?

dnolen21:06:00

it took me 3 hours to figure out how to put this Webpack post together

dnolen21:06:05

and I still got it wrong

dnolen21:06:13

gimme a break 🙂

johanatan21:06:25

fair enough. coming from something like Visual C++ or IntelliJ is a different experience though

dnolen21:06:37

ha really?

dnolen21:06:47

IntelliJ magically figures hodge-podges

dnolen21:06:51

that’s why it costs $800 a year

johanatan21:06:20

yes, but those hodge-podges are hidden from you. 🙂

johanatan21:06:03

anyway, i'm not complaining and i've certainly gotten more accustomed/comfortable with this aspect over time

isak21:06:11

it's usually the frameworks that glue things together in a nice way, no?

dnolen21:06:57

back to the main point - yes documentation is a problem - we need to work on that

dnolen21:06:04

@bfast I thought the UMD thing was a bug (regression or UMD pattern it couldn’t handle) with Google Closure? We bumped that today - will be in the next release - tomorrow

dnolen21:06:28

but also :foreign-libs is not magic 🙂

dnolen22:06:10

you should be able to use Webpack to create something which provides cljsjs.react - if you’re trying to work around something

dnolen22:06:42

I might extend the Webpack post to clarify that

dnolen22:06:00

:foreign-libs was designed to be overrideable since the very beginning because you may need to work around stuff

tungsten22:06:27

That would be great if there is a fix. 🙂 I obviously don't have enough understanding of things to make things work yet, so I couldn't tell you what my specific issue was. Last I remember I was stuck at something like "Error: Cannot find module '@cljs-oss/module-deps'" .. but I will document everything this weekend. I am hoping to avoid workarounds and understand the root issues I am facing

dnolen22:06:46

@bfast that’s covered in my post

dnolen22:06:32

you need :npm-deps false if you have node_modules and you don’t want to use it

dnolen22:06:58

@bfast just confirmed this works

dnolen22:06:12

I can run Reagent 0.8 from my own build of React via Webpack

dnolen22:06:19

I’ll add this to the post

dnolen22:06:34

it’s also comically short

johnj22:06:40

@dnolen does cljs infers (via closure) all externs for react without warnings or does react complies to closure rules?

tungsten22:06:45

ty @dnolen I have put together a small project that shows my frustrations with the tooling... For the life of me I cannot tell what is going on with this project and why it doesn't work. https://github.com/briangorman/es6test . .... I am trying to add a single es6 module as a test that foreign libs works, but somehow the project is trying to invoke node. Even on a computer that has never had node installed. I'm trying to run the project with "lein figwheel".... maybe I'm dim

dnolen22:06:01

@lockdown- externs inference is just about automating externs

dnolen22:06:20

@bfast :npm-deps false in your build config

dnolen22:06:59

I just verified that the Webpack override works and externs inference under advanced compilation has you covered w/ a small tweak to master @bfast

dnolen22:06:11

@bfast I would look at that but it’s seriously lacking in any kind of meaningful information

dnolen22:06:19

please describe the problem on the repo so I don’t have to run the thing first

bhauman22:06:38

cannot find module @cljs-oss/module-deps

dnolen22:06:56

paste the whole trace please

dnolen22:06:07

and what happens under --verbose

dnolen22:06:54

also :npm-deps false may be limited to master

bhauman22:06:12

oh well that's probably the problem

dnolen22:06:23

tomorrow 🙂

tungsten23:06:52

@dnolen ok next time I will update the readme. It looks like Bruce provided what you requested? Thanks for looking at this

dnolen23:06:20

demonstrates that advanced builds work with externs inferece

👍 4
dnolen23:06:44

I think release should address a lot of complaining 🙂

dnolen23:06:55

quite valid complaining for sure

tungsten23:06:00

This project was generated from "reagent-frontend" template

dnolen23:06:17

right but it doesn’t matter what template you use

dnolen23:06:24

the guide shows you how to make it work regardless

tungsten23:06:50

Ok awesome, I will give it a whirl tomorrow.

johnj23:06:39

@dnolen why do you use warn-on-infer here https://clojurescript.org/guides/externs but not on your react/webpack example ?

dnolen23:06:05

you don’t need to use it

dnolen23:06:01

*warn-on-infer* is just an extra thing for people who are extra picky and who want to control the scope of externs inference

dnolen23:06:04

in theory it would affect code size, but fortunately ClojureScript users aren’t generating clashing names due to ubiquitous munging etc.

dnolen23:06:33

when you’re writing a library that interop with some foreign lib you might write something like

dnolen23:06:54

(.getX ...)

dnolen23:06:21

externs inference will produce Object.getX instead of something more specific

dnolen23:06:44

but honestly it’s probably the case that this won’t really affect most users - I did this as a completeness thing just in case

dnolen23:06:06

note that none of this matters for overriding cljsjs/react

johnj23:06:08

Object.getX as in the object object ?

dnolen23:06:15

somebody has already written the interop stuff

dnolen23:06:40

@lockdown- I honestly wouldn’t worry about it too much 🙂

dnolen23:06:58

if you’re curious I would refer to Google Closure docs on externs or the Google Closure book

johnj23:06:05

are the conditions for inference that all modules are removed and the final bundle is ES5?

dnolen23:06:21

I don’t know what you’re asking

dnolen23:06:28

externs inference is for one thing and one thing only

dnolen23:06:34

not renaming stuff that can’t be renamed

dnolen23:06:55

previously you had to write externs by hand when using foreign libs

dnolen23:06:05

or hope that they were written for you a la CLJSJS

dnolen23:06:09

now you don’t need to care

👍 4
johnj23:06:02

was just curious about the use of webpack, that somehow is was needed in cljs to remove all the module stuff and es6 stuff, but I guess is needed for the same reasons is needed in JS (sorry, new to this)

dnolen23:06:07

it’s needed in the sense that there’s demand for it

dnolen23:06:51

shadow-cljs does a good job already of course - but we’d already invested a lot of effort ourselves so this just polishing up what’s there and documenting it

dnolen23:06:16

for example externs inference is actually based on a idea I had years ago that Maria Geller did the foundational work for 3 years ago http://mneise.github.io

johnj23:06:16

Ok, was confused at first cause I though inference was closure feature instead of cljs one

johnj23:06:49

so all these trouble is because some want to avoid using webpack(or js tools, even clojure tools?) at all costs? 😛

johnj23:06:26

so cljs is actually ahead of typescript in this area or are TS declaration files is a different thing?

dnolen23:06:53

this is to support usage of other tools

dnolen23:06:10

i.e. you want to use some random React component

dnolen23:06:22

but that nearly always means you need to build React yourself

👍 4