Fork me on GitHub
#clojurescript
<
2017-06-05
>
mikeb00:06:44

Ok, weird I must be missing something with cljs macros. All parameters to macros seem to be the symbol/form and not the evaluated values.

noisesmith00:06:34

that's what macros are- the evaluated parameters happen well after the macro is gone

noisesmith00:06:07

a macro takes a form (with symbols in it, usually), and returns a new form (usually using the same symbols)

mikeb00:06:25

How to call a macro with runtime values then?

noisesmith00:06:40

by compiling code at runtime

mikeb00:06:56

by evaluating the defmacro?

mikeb00:06:01

then calling it?

mikeb00:06:08

I must be missing a step.

noisesmith00:06:40

macros are meant for syntax, they don't act on values, they act on forms

noisesmith00:06:54

(which are values consisting of literal data in a source)

mikeb00:06:36

when you say that, it's different than jvm clojure then?

noisesmith00:06:48

no, same goes for jvm clojure

mikeb00:06:49

Because when I write the same macro in clj, it works fine.

noisesmith00:06:58

your macros don't see runtime values, they see the forms in the source

noisesmith00:06:28

are you trying to use the macro from the same compilation unit thatdefines it? that doesn't work in cljs

mikeb00:06:31

the macro itself, yes, but when calling the macro, it's using the forms in source as well, but only in cljs.

mikeb00:06:07

ah, that might be it. let me try that.

ssaul03:06:22

#om has anyone gotten the hello example (or any of the examples) in the om repo to work? I get the following error. clojure.lang.ExceptionInfo: Invalid :refer, macro cljs.pprint/deftype does not exist in file examples/hello/out/cljs/pprint.cljs {:tag :cljs/analysis-error} It seems I am not alone. @pedroteixeira revieved the same error 2017.05.28 https://clojurians-log.clojureverse.org/om/2017-05-28.html Is this something I should post on the github as an issue? Or is there some work around. I am able to get a clojure project compiled with cljs/pprint.cljs in the out folder when doing the clojurescript getting started tutorial. I am not sure if there may be an issue with lein cljsbuild.

iku00088803:06:03

Are there any cljs http libs out there that can handle different response formats between success/error?

akiroz04:06:14

Anyone know how cljs.test actually runs my tests? (like what environment does it use?)

gmercer04:06:43

@ssaul @pedroteixeira try bumping the clojurescript version to 1.9.562

ssaul04:06:13

I got the following warnings:

WARNING: Use of undeclared Var cljs.pprint/pprint at line 15 examples/hello/out/devcards/util/utils.cljs
WARNING: Use of undeclared Var cljs.pprint/with-pprint-dispatch at line 23 examples/hello/out/devcards/util/utils.cljs
WARNING: Use of undeclared Var cljs.pprint/code-dispatch at line 23 examples/hello/out/devcards/util/utils.cljs
WARNING: Wrong number of args (1) passed to UUID at line 564 examples/hello/out/cljs/reader.cljs
WARNING: Use of undeclared Var clojure.string/starts-with? at line 822 examples/hello/out/cljs/analyzer.cljc
WARNING: Use of undeclared Var clojure.string/ends-with? at line 972 examples/hello/out/cljs/analyzer.cljc
WARNING: Use of undeclared Var clojure.string/starts-with? at line 2643 examples/hello/out/cljs/analyzer.cljc
WARNING: Can't take value of macro cljs.core/require at line 15 examples/hello/out/cljs/nodejs.cljs
WARNING: require already refers to: cljs.core/require being replaced by: cljs.nodejs/require at line 15 examples/hello/out/cljs/nodejs.cljs
but it compiled. but when i go to the browser I get the following errors in the console.
Uncaught Error: Assert failed: No target specified to om.core/root
(not (nil? target))

gmercer04:06:44

that get's you past compiler failing - just lots of warnings but trying to open index.html you get an assertion that the target is not specified

ssaul04:06:32

yeah, i see what you are saying. Show I use an earlier version of om? Is there anywhere, maybe in a readme or that I missed that says what version of clojurescript works with what version of om?

ssaul04:06:42

I just assumed that the master would work

gmercer04:06:43

document.getElementById("app")
returns
<div id="app"></div>

ssaul04:06:58

with the example

ssaul04:06:07

oh ok, i will try what you just sent

gmercer04:06:01

I added a breakpoint at

(om/root widget app-state
  {:target (.getElementById js/document "app")})

ssaul04:06:36

i tried document.getElementById("app") but I just got back null in the browser. ohh you are doing some real debugging. nice!

ssaul04:06:45

i have not even gotten to that stage yet

gmercer04:06:14

I see the Map being created and the Keyword being created ... back in 30mins ..

ssaul04:06:27

ok no prob.

gmercer06:06:05

hmm ... outta my depth here ...

([f value {:keys [target tx-listen path instrument descriptor adapt raf] :as options}]
    (assert (ifn? f) "First argument must be a function")
    (assert (not (nil? target)) "No target specified to om.core/root")
options seems to have all the values but the keys have not been extracted
options.root.arr[0].tail
(2) [c…s.c…e.Keyword, div#app]
 0:
  cljs.core.Keyword
  cljs$lang$protocol_mask$partition0$: 2153775105
  cljs$lang$protocol_mask$partition1$: 4096
  fqn: "target"
  name: "target"
  ns: null
  _hash: 253001721
  __proto__: Object
1: div#app
length: 2
__proto__: Array(0)

gmercer06:06:31

need someone with more js/cljs-fu than I can offer

ssaul06:06:19

nah, it is all good. you have already helped greatly. I will take a look at what you have sent. Thanks!

macalimlim07:06:39

Hi is there a way to hotload clojurescript apps in production?

lxsameer08:06:15

Some one suggested shadow-cljs

pesterhazy11:06:15

I'd like to propose a new variant of cljsjs/react called cljsjs/surrrogate-react, which only includes the externs file and an empty react.js

pesterhazy11:06:24

Including this dep would make it possible to (require 'cljsjs.react) without errors, except that it wouldn't actually include react source files

pesterhazy11:06:10

Requiring this would be a cleaner version of including src/cljsjs/react.cljs in your project

pesterhazy11:06:13

We'd also need cljsjs/surrogate-react-dom.

pesterhazy11:06:28

@juhoteperi what do you think of this idea?

juhoteperi11:06:28

Sounds like a workaround and won't solve using npm-deps with Reagent etc.

juhoteperi11:06:44

@pesterhazy React 16 will also drop react-with-addons so react/react-dom/react-dom-server can all be provided by single cljsjs package

juhoteperi11:06:18

At least that will make using alternative versions a bit easier as there one less exclusions will be needed

pesterhazy11:06:24

yeah it's a workaround, but a useful one for a lot of people

pesterhazy11:06:46

for example, everyone in react-native land has this weird empty namespace in the src folder

pesterhazy11:06:17

having a surrogate dependency available from a trusted source would reduce that to a single line in project.clj

juhoteperi11:06:30

The externs could be provided in separate package, that would help a bit

pesterhazy11:06:51

although I'm not sure we even need externs for React

juhoteperi11:06:10

with npm-deps they are at least required, I don't know about react-native

pesterhazy11:06:44

I'm guessing reagent will work without externs, but not sure about the other wrappers

pesterhazy11:06:13

would you be open for a PR to add surrogate-react?

juhoteperi11:06:41

Hmm, perhaps this would be good opportunity to also deprecate react-with-addons and merge the three packages

pesterhazy11:06:17

wouldn't react and react-dom still be separate?

juhoteperi11:06:37

One package can provide the all three foreign-lib namespaces

pesterhazy11:06:12

yes that's true, but you might want to selectively mock out only react or react-dom

juhoteperi11:06:17

Merging the packages prevents problems with mismatched react & react-dom dependencies

juhoteperi11:06:56

Hmm, I think that can be achieved by adding local foreign-lib entry for react or react-dom

juhoteperi11:06:17

Not sure if local cljs namespace would also overwrite a foreign-lib

pesterhazy11:06:38

not sure I understand

juhoteperi11:06:23

If cljsjs/react provides both cljsjs.react and cljsjs.react-dom foreign-libs, those can be mocked out by providing local foreign-lib entry in the project, or with cljs namespaces with the same name

pesterhazy11:06:15

but that would still require adding an empty js file to your project, right?

juhoteperi11:06:07

But how common it is to mock only one of them?

pesterhazy11:06:24

react-native project, for example, don't require react-dom

pesterhazy11:06:50

but you're right, that wouldn't mean selectively mocking out only one

pesterhazy11:06:20

so your idea is that cljsjs/react provides both libs, and you just don't get react-dom if you don't require it?

juhoteperi11:06:39

But I guess that can cause problems with Reagent as it has require on react-dom

pesterhazy11:06:07

honestly I always liked the fact that the dependencies were explicit

pesterhazy11:06:25

it mirrors the way react and react-dom are packaged by facebook

juhoteperi11:06:33

My thinking is that in future we need to somehow remove these dependencies from libraries (Reagent) and let the users select in project select if React is provided from npm-deps or cljsjs or whatever

juhoteperi11:06:38

But not sure yet how we can achieve this

juhoteperi11:06:11

Yeah that is true also

pesterhazy11:06:05

I remember when I first got into reagent, the empty react namespaces confused the hell out of me

juhoteperi11:06:38

PR welcome for surrogate packages

juhoteperi11:06:36

Probably best to modify react build.boot to build these artifacts so it is automatically updated with new versions and that way you can also easily include the externs

pesterhazy11:06:16

yeah I had a quick look at how to modify it

juhoteperi11:06:38

https://github.com/cljsjs/packages/blob/master/react/build.boot#L55 perhaps a another with-files here which doesn't use download but for example sift to copy a empty file in resource-paths to a correct path & pom with modified name etc.

pesterhazy11:06:37

what does with-files do here?

juhoteperi11:06:40

It is implemented just before the package-part, it creates a filtered copy of fileset and runs the given task pipeline with that fileset and merges the results back to original fileset

pesterhazy11:06:58

ok I'll give it a try

charafau11:06:29

hello everyone, i’m quite new to clojurescript so here’s my question - what’s the best way to write react apps now? om.next + figwheel + re-natal ?

dnolen12:06:28

@charafau I’m not sure about “best”. om.next is one way - reagent/re-frame are also very popular way. You also have Rum. Conceptually om.next is more like Relay / Relay Modern than plain React. re-frame is more like say Redux.

charafau12:06:56

oh, I’m familiar with redux, so maybe will go for re-frame for now

mfikes12:06:48

@charafau You mentioned re-natal. For mobile, be sure to check out #cljsrn and http://cljsrn.org

Pablo Fernandez15:06:25

When using reagent/create-class and defining :component-will-update, is it possible to call component-will-update on a child component?

iku00088815:06:36

Does ns not work in ClojureScript

iku00088815:06:55

I guess a work around could be taking the namespace of a random ::keyword , but I do have a feel there is something better

dnolen16:06:36

@iku000888 doesn’t work, can’t be a dynamic var like in Clojure - it could be a file level constant - you can get at the current ns via your own macro though.

vinnyataide18:06:07

hello good sirs. may I ask if figwheel has a proxy option?

samueldev21:06:12

i feel like im taking crazy pills

samueldev21:06:21

does map equality not work the way I think it does in cljs?

samueldev21:06:30

^ that evaluates to false

joelsanchez21:06:13

Well "updatedBy" is certainly not the same as "updated-by"

samueldev21:06:24

oh god damnit

andrewboltachev22:06:20

Hello. Is it possible to compile ClojureScript to output, which I'd be able to later compiler with Google Closure compiler myself (Please don't ask what for 🙂 )?

dnolen22:06:06

@andrewboltachev that’s optimizations :none

andrewboltachev22:06:22

uhm... still have that ERROR - Missing @define annotation

dnolen22:06:40

sounds like you’re either using JS module processing in your project or something less typical like that

dnolen22:06:03

in anycase :none doesn’t use Closure at all

dnolen22:06:19

as long you aren’t using Closure for processing JS stuff

andrewboltachev23:06:06

in fact I'm trying to make advancedly-compiled bundle which consists of regular CLJS project, and bunch of JS libraries as well

andrewboltachev23:06:37

i.e. I'm trying to concatenate two bundles and use compiler on that result

andrewboltachev23:06:19

(I wanted to try if this would work, i.e. I won't need externs that way)

dnolen23:06:21

hrm, you need to be a little bit more clear on the exact steps you are taking

dnolen23:06:37

and the error you’ve given is meaningless w/o knowing more about it

andrewboltachev23:06:31

ah yep, I'd better try just to compile the CLJS :none optimized bundle alone

dnolen23:06:31

also just because you’re passing JS into Closure doesn’t mean you won’t need externs

dnolen23:06:44

this is a common misunderstanding

andrewboltachev23:06:05

(but wanted to try anyway)

dnolen23:06:13

you always need externs if you have dynamic property stuff going on

andrewboltachev23:06:15

I know that e.g. React gets around with all that keyMirror etc things

dnolen23:06:20

doesn’t matter if the code is or isn’t external

andrewboltachev23:06:43

i.e. there's a reason for keyMirror to exist

dnolen23:06:02

React needs externs for example

dnolen23:06:23

well that’s news to me since we can compile React from NPM and we still needed to supply externs, but maybe there’s new changes I’m not aware of

andrewboltachev23:06:55

ah well... I'm providing React separately btw

dnolen23:06:09

but in anycase, the point about externs stands

dnolen23:06:16

irrespective of how React may work around it

andrewboltachev23:06:00

got it. thanks @dnolen So I'd have either to provide externs exhaustively for all the code or just go for :simple

dnolen23:06:29

yes, I don’t think you’ll be able to provide a better pipeline for mixed JS / ClojureScript that’s advanced compilation friendly than the system we already provide

dnolen23:06:31

well in theory you could of course but a lot of effort has gone into ClojureScript and tools like shadow-build, starting from scratch doesn’t sound particularly productive at this point 🙂

andrewboltachev23:06:16

uhm, the exact point out there that I wanted won't work anyway. So yes, unlikely productive 🙂 Only I might say that real projects actually start needing all that 3-rd party JS components very quickly, and there ain't necessarily externs for all of them (the components themselves are in ES6 etc)

dnolen23:06:38

yes and there’s nothing you can do about that - advanced compilation is the tradeoff

dnolen23:06:43

not going to change

andrewboltachev23:06:03

don't know if this is very interesting

andrewboltachev23:06:46

but it's not a standard way: > Now, to fool Reagant into thinking that these packages already exist - we’re going to create empty namespaces. <...>

dnolen23:06:09

it’s pretty typical yes

dnolen23:06:45

the other way is to use :npm-deps but your mileage may vary and integrating with libs that use cljsjs.react is challenging

dnolen23:06:09

though I believe even that is probably solveable in Reagent or Om etc. by adding a bit of indirection to React

andrewboltachev23:06:22

uhm btw interesting if :npm-deps use npm or might use e.g. yarn as well (or rather independent)

dnolen23:06:57

seems less important than making it work well for npm first

dnolen23:06:43

so I think for the greatest impact, try to get :npm-deps working for your use case and report issues

dnolen23:06:07

understandable if not practical because you’re trying to get this working for something you are trying to ship now - but that would be path towards the future

dnolen23:06:07

@andrewboltachev it did get me thinking a bit about the problem, I posted some thoughts in #cljs-dev if you’re interested

andrewboltachev23:06:08

@dnolen got it, yes, thanks