Fork me on GitHub
#clojurescript
<
2018-02-18
>
jmb00:02:25

Hey guys. I'm having a problem with my clojurescript cljsbuild setup. I'm trying to have a <button>'s onclick attribute set to a Clojurescript function in my core.cljs file defined with an ^:export meta tag. I included the outputted file from my js folder in resources/public which is clojurescript.js. I set the onclick attribute of the button to cljs.core.greet(), but when I click the button, I get that cljs is not defined. What's going on here ?

jmb00:02:53

I have advanced optimizations for my Clojurescript build in case it helps

hlolli00:02:07

@jmb do you have a function greet in a file cljs/core, given that you have source-path "src" (maybe among other source-paths) then it would be "ROOT/src/cljs/core.cljs" in which file you have

(ns cljs.core)
(defn :^export greet [] (println "Hello World"))
if so, does it work with other optimizations than :advanced?

jmb00:02:23

@hlolli Yes I have that exact same function except it has (js/alert "It worked") inside. I'm experimenting right now in another branch if it works with other optimizations like :none

hlolli00:02:40

it shouldn't matter, Im right now running exported function in an advanced compiled browser code. Actually on shadow-cljs, it has some extern stuff prepacked so it may differ.

jmb00:02:24

I suppose. I just wanted to simply setup Clojurescript so I can provide basic functionality to the site without having to write Javascript

hlolli00:02:20

yes, I tested this and it works, I can send you a zip file if you want?

jmb00:02:37

That'd be great

koala punch13:02:33

hi, i’ve been trying to get code completion working with either lein figwheel or boot cljs with no success

koala punch13:02:44

this is using vim

koala punch13:02:50

anyone managed to get this working?

koala punch13:02:21

seems to be fine for standard clojure, but clojurescript seems to fail. i think it’s something to do with integration between fireplace and the clojurescript repl

koala punch13:02:02

i can evaluate the code, but just can’t seem to get the inline docs or code completion to work

koala punch13:02:10

sorry i didn’t realise there is a vim-fireplace channel, i’ll ask in there

mpcarolin14:02:31

I too had issues and I think the solution is in properly setting up piggieback, the middleware for interfacing clojurescript on an nREPL. I ended up using Cursive with a vim extension instead, but I hope you work it out. It should work out of the box.

koala punch23:02:38

hi, just read this

koala punch23:02:46

i got it all working today with vim

koala punch23:02:51

so let me know if you need any help

koala punch23:02:09

i had a lot of problems with the boot-cljs repl, but once i started using figwheel things got a lot easier

koala punch23:02:25

i now have automatic code complete working in neovim, using piggieback 🙂

koala punch23:02:56

using it to learn reagent, which seems to be a super nice library

alex-dixon17:02:00

I’m trying to use transit to send and receive messages between a JS and CLJS app. I’m using transit-js for JS and transit-cljs for CLJS. Do I need to write custom deserializers for receiving EDN in JS as JSON?

alex-dixon17:02:09

Reading on the JS side is returning a TransitArrayMap. I was expecting JSON 😕

noisesmith17:02:00

transit represents a lot of things json can't, I think you'll need to make your own translator

noisesmith17:02:24

if everything needs to be a subset of json, you don't need transit and you can just use a json formatter directly

alex-dixon18:02:11

@noisesmith What would you suggest?

alex-dixon18:02:29

I’m communicating with a JS app that expects JSON, CLJS app is sending EDN with keywords, otherwise nothing fancy. I thought clj->js was slow, so introduced transit to avoid that

noisesmith18:02:16

clj->js is slow, but if you know the overall shape of the data you need to make, you can do something much more performant

noisesmith18:02:35

the other option is for the js to use the actual cljs data types

thheller18:02:06

haven't done any benchmarks but I doubt that clj->js is slower than transit.

thheller18:02:55

thats comparing reading JSON and then transforming via js->clj not clj->js

thheller18:02:14

if you are crossing the network then yes transit will probably be faster. if not clj->js should win.

alex-dixon18:02:42

To clarify I’m doing that operation as well. Just trying to have a JS and CLJS communicate with data as performantly as possible, each with their native data formats (EDN for CLJS, JSON for JS)

alex-dixon18:02:17

Hm ok. It’s across a webworker with postMessage/onmessage

thheller18:02:27

ah ok. then yes transit will be better.

alex-dixon18:02:03

Ok. Phew 🙂. So only problem I think I’m having is that JS side transit-js/read returns some transit-js object, not JSON. Trying to get to JSON

noisesmith18:02:03

the string is json before you call transit-js/read, if you use :json or :json-verbose as the format

noisesmith18:02:19

it might not be easy to use json, but it will definitely be json

alex-dixon18:02:39

Ah. Ok. So that gets somewhere. If the CLJS side encodes in :json-verbose I get vanilla JSON that I can parse on the JS side

alex-dixon18:02:38

I thought :json was faster, so I was using that. The raw message I receive with it is transit encoded. Reading it with transit-js produces a transit Javascript object, which I’d then need to turn into JSON…

alex-dixon18:02:58

Should I call it good enough with using :json-verbose?

noisesmith18:02:38

the raw message the :json encoding creates is valid json, but constructed in such a way as to optimize message size and memory usage

noisesmith18:02:48

rather than being an inutitive mapping of the input

noisesmith18:02:35

it really depends on what your performance and space needs are, but I'd suspect using :json-verbose would be ideal

alex-dixon15:02:09

Thanks for your help

mfikes20:02:22

@goldsmith.tee It would be interesting to know whether the patch in https://dev.clojure.org/jira/browse/CLJS-2529 resolves your Java 9 issue. Details on trying a patch are here http://blog.fikesfarm.com/posts/2016-02-22-trying-clojurescript-paches.html

eoliphant23:02:46

Hi, I’m trying to use the npm-deps feature per this post (https://clojurescript.org/news/2017-07-12-clojurescript-is-not-an-island-integrating-node-modules) I’m using the aws-amplify library. The build seems to be fine, a package.json was created, I see the lib in node-modules, etc. I’m running into an issue when I try to require the module. In both requires’s in the repl and :require in namespace declarations, I’m getting the assertion failure regarding “aws-amplify” not being a symbol. I’ve seen similar issues discussed in the archives, but it’s not clear what the solution is. I’m on 1.9.946, most of the stuff I saw discussed the issue in the context of earlier versions

justinlee00:02:22

@U380J7PAQ I’ve not had good luck with that feature. It’s very hard to figure out what is wrong when it doesn’t work. I’d suggest either using foreign-libs or, if you are importing a lot of stuff via npm use shadow-cljs as that allows you to just use npm or yarn directly. I’ve had a really good experience with shadow

eoliphant00:02:10

ok thanks, that’s great to know. I saw something about shadow-cljs, will check it out I know this is a knotty problem and lots of ‘clogenuises’ are working it, but it’s kinda hard to get a clear read on what’s best like ‘now’ lol Thanks again

juhoteperi08:02:45

ClojureScript master should also have much improved support for Node packages (though might also have regressions)