Fork me on GitHub
#clojurescript
<
2018-05-02
>
mikerod00:05:07

@pri also you can take a look at https://github.com/pesterhazy/presumably/blob/master/posts/double-bundle.md Not the same as built In support. But a potential alternative.

richiardiandrea02:05:55

This is very interesting thanks for sharing

👍 8
mikerod02:05:10

No problem!

pre02:05:08

Thanks @mikerod @emccue, will do. I hoped cljs core to have smoother Js module integration—instead we have a dozen repls and libs forking out flavors and the documentation is still broken.

👎 4
john14:05:40

He could probably use our help though

mfikes14:05:13

Yeah, if you see an issue, filing a JIRA with a minimal repro would help. (Perhaps this is easy to do given that an example on the site appears to be busted.)

Alex Miller (Clojure team)02:05:01

Maybe instead of crapping on busy people working hard, you could try helping. Or just being kind.

👍 12
tdaudelin03:05:24

Hey all, I have what I hope is not an impossible problem in clojurescript 🙂

tdaudelin03:05:33

I'm trying to assign a function call as the value of an html attribute. E.g. something like <div onlogin="someFunction();"></div>

tdaudelin03:05:20

My first thought to do this in cljs is something like this: [:div {:onlogin #(someFunction)}]

tdaudelin03:05:56

but that unfortunately renders as <div onlogin="function() { someFunction(); }"></div> which does not work

tdaudelin03:05:24

Has anyone experienced this?

tdaudelin03:05:55

The only success I've had getting this to work correctly is if I write this gross hack: [:div {:onlogin "full.path.to.someFunction();"}]. I haven't tested it with minification yet but I very much doubt it would work

WhoNeedszZz03:05:44

The namespace is required

tdaudelin03:05:02

Hmm, I guess the core of what I'm asking is, if #(some-function) compiles to function () { some-function(); }, then what do I need to do to get (function () { some-function(); })(); instead?

dpsutton03:05:52

why not just (some-function) instead of #(some-function)?

dpsutton04:05:16

does just invoking it not work?

tdaudelin04:05:05

Ah, because I'm not trying to invoke it at the moment when the html is being rendered

tdaudelin04:05:40

rather, I'm passing instructions for how to call my function to a component

dpsutton04:05:13

{:onlogin someFunction} should work then

tdaudelin04:05:58

interesting... let me try

dpsutton04:05:37

this is right out of our codebase: :onClick (fn [_click] (toggle-biller eid))

tdaudelin04:05:00

Hmm, no luck. That just resulted in a named anonymous function instead: <div onlogin="function path$to$some-function() { ... }"></div>

tdaudelin04:05:38

^ in response to {:onlogin some-function }

tdaudelin04:05:18

Yeah it's super weird that :onClick works just fine with anon functions 😕

tdaudelin04:05:28

I guess I'll be more specific about my problem. I'm trying to integrate the facebook sdk with my re-frame app: https://developers.facebook.com/docs/facebook-login/web

tdaudelin04:05:20

I want to use the official facebook login button and the example they give is

<fb:login-button scope="public_profile,email" onlogin="checkLoginState();">
</fb:login-button>

tdaudelin04:05:27

notice the onlogin attribute

tdaudelin04:05:02

it looks like they expect literal javascript as a string that they can call exec() on

WhoNeedszZz04:05:40

(defn state-ful-with-atom []
  [:div {:on-click #(swap! click-count inc)}
   "I have been clicked " @click-count " times."])

henrik07:05:48

So, compiling with NodeJS as target.

clj -m cljs.main --watch src --target node --output-to resources/server/main.js -c landing-page.core
This worked fine until I decided to require ["fs" :refer [readFileSync]]. Now it throws
Caused by: clojure.lang.ExceptionInfo: No such namespace: fs
So I created a project.clj and configured the same deps and options as above, and ran lein cljsbuild. This works just fine, it pulls in the fs module from Node without complaining. Any ideas as to what might make clj fail to find fs?

juhoteperi07:05:05

@henrik Try adding --output-dir/`-d` option

henrik07:05:02

@juhoteperi Cheers, but same difference I’m afraid.

henrik07:05:40

So, these are my cljsbuild options:

:cljsbuild {
              :builds {:dev {:source-paths ["src"]
                             :compiler {:main "landing-page.core"
                                        :output-to "resources/server/main.js"
                                        :output-dir "out"
                                        :target :nodejs
                                        :optimizations :none
                                        :source-map true
                                        :pretty-print true}}}})
As compared to:
clj -m cljs.main --watch src --target node --output-dir out --output-to resources/server/main.js -c landing-page.core

henrik11:05:52

@mfikes Oh yeah, that’s the one. Voted. 🙂

✔️ 4
juhoteperi11:05:57

@mfikes @henrik That issue needs probably more information because this works with some tools with NodeJS target (e.g. Lein https://github.com/reagent-project/reagent/blob/master/prerender/sitetools/prerender.cljs#L15)

dehli15:05:33

Anyone have success getting their repl working with cljs?

dehli15:05:25

I’ve started my repl using the node env from a terminal, but it doesn’t seem to be “connected” b/c I get that the existing functions are undeclared after I call in-ns

dehli15:05:07

This was the command I ran clj -m cljs.main --repl-env node from the project directory (at the level that deps.edn lives).

pesterhazy15:05:42

@dehli what exactly are you trying to do?

pesterhazy15:05:01

When I run that command I get this

$ clj -m cljs.main --repl-env node
cljs.user=> (+ 1 3)

dpsutton15:05:41

@dehli are you aware of the difference between in-ns and loading and requiring?

dehli17:05:14

I assumed that if I ran the repl from the project root it would require the namespaces for that project

dehli17:05:50

Basically, I’d like to be able to run the functions that I have in my src folder

dehli17:05:04

Ideally through emacs 🙂

dpsutton17:05:06

of course. i was asking if you were familiar with the difference between essentially declaring yourself in a namespace (`in-ns`) and loading/requiring to make sure that namespace is populated

dpsutton17:05:47

if you are using CIDER, look into cider-load-buffer-and-switch-to-repl-buffer

dehli17:05:10

Ahhh, sorry I misunderstood. Not really 🙂 But I’m reading through this: https://clojurescript.org/reference/repl

dpsutton17:05:18

if you give that a prefix argument it will also put you in that ns as well. this chord is baked into my muscle memory

dehli17:05:33

Thanks! I’ll give that a go. So can you eval cljs functions and eval them from within emacs?

dehli17:05:41

similarly to how you can do it in clojure

dpsutton17:05:28

absolutely. just like there's a cider-jack-in there's a cider-jack-in-clojurescript and you get all the same goodies

dehli17:05:58

that’s so cool! i’ll work on getting my emacs config setup with that. thanks!

dpsutton17:05:11

there's a #cider channel for questions about that and a #beginners channel to help you get up and running if you want to chat more

dpsutton21:05:39

(assoc {} :a 2 4)
{:a 2, 4 nil}
bug or acceptable garbage in garbage out?

dpsutton21:05:49

this is an error in clojure

thheller21:05:14

I'd say bug

dpsutton21:05:42

thanks much