Fork me on GitHub
#clojurescript
<
2016-03-22
>
ag00:03:40

how do I tell compojure to serve files out of ‘node_modules’ folder? I don’t want to copy it inside resources/public

ag00:03:57

what’s the difference between files and resources?

bostonaholic00:03:57

I'm going to guess that resources can only grab files that are in the classpath?

ag00:03:59

so I can’t find a way to serve anything statically outside of resources/public folder

bostonaholic00:03:00

have you tried the :root option?

ag00:03:08

@bostonaholic: yeah but what :root ’s gotta be? ../.. or just “” or nil? I’m trying all sorts of things

ag00:03:39

I added to my page

[:link {:href "/font-awesome/css/font-awesome.css" :rel "stylesheet" :type "text/css"}]

ag00:03:12

and now trying this: (resources "/node_modules" {:root nil }) and nothing

bostonaholic00:03:19

(files "node_modules" {:root "../.."}) would be my best guess

bostonaholic00:03:43

root will have to be in relation to your resources directory

ag00:03:30

I’ve tried that

bostonaholic00:03:37

also will depend on your web server configuration and probably a whole host of other things

bostonaholic00:03:27

depending on your web server, you may need to restart it when changing compojure routes

ag00:03:04

any other stuff works beautifully when it’s in resources/public folder. I want to serve things right from node_modules

ag00:03:41

or matter of fact form any other place outside of resources

bostonaholic00:03:32

if you add node_modules to the classpath, you could reference it probably with resources

ag00:03:27

I tried adding node_modules to :resource-paths of profiles.clj - still nothing

weavejester01:03:52

resources will serve files from the classpath

weavejester01:03:08

So if the resources directory is on the classpath

weavejester01:03:29

Then public on the classpath would be equivalent to resources/public

weavejester01:03:18

If you add node_modules to :resource-paths, then the subdirectories of node_modules will be on the classpath.

ag01:03:48

@weavejester: so what exactly it’s has to be to work? :resource-paths ["node_modules”]

ag01:03:13

url to file in index.html /font-awesome/css/font-awesome.css

ag01:03:31

(files “/“)

ag01:03:36

like that?

ag01:03:16

I think I’ve tried every possible variation, it still doesn’t work 😞

ag01:03:50

compojure hates me

bostonaholic01:03:19

use resources instead of files

bostonaholic01:03:56

since you're adding node_modules to the classpath

ag01:03:27

nope… still nothing

bostonaholic01:03:55

what web server are you using?

ag01:03:29

ring/compojure

bostonaholic01:03:11

those aren't web servers. jetty, immutant, etc.

ag01:03:19

hold on… I think it worked

ag01:03:01

what I had to do is (resources "/" {:root "" })

ag01:03:15

and all the stuff above

bostonaholic01:03:26

that will mean that every file in your classpath is accessible

ag01:03:22

errrrr… damnit… so what do I do then?

ag01:03:54

I think you’re wrong… everything in node_modules is accessible, yes… everything in resources/public accessible yes. but nothing else seem to be

ag01:03:35

eh… shit… no you’re right… I just tried and I was able to download project.clj - not good

bhauman01:03:35

The root parameter is relative to the resource-path

bhauman01:03:40

You need to add nose modules to your resource paths in your project clj

bhauman01:03:41

Oh looks like you have already done that

ag01:03:09

Yeah, it seems to be working now as I wanted. I’m slightly concerned that I was able to access project.clj - I think something was broken here even before I started simple_smile

bostonaholic01:03:33

I figured that wasn't your intended behavior

mangr3n02:03:50

Is there any effort to provide a 100% pure javascript implementation of clojurescript compilation?

wei06:03:08

what’s a good way to hook into mouse and keyboard events without interfering with existing handlers? i.e. looking for a translation of this:

var idleTime = 0;
$(document).ready(function () {
    //Zero the idle timer on mouse movement.
    $(this).mousemove(function (e) {
        idleTime = 0;
    });
    $(this).keypress(function (e) {
        idleTime = 0;
    });
});

urbanslug06:03:54

What is the type of functions returned by sablono "stuff"

rauh06:03:06

@urbanslug: They're translated into React.createElement calls.

wei06:03:19

@rauh: helpful, thanks

urbanslug06:03:59

rauh: hmmm thanks, I can’t really quite understand what that means though.

urbanslug06:03:47

We just use JS to add that element.

urbanslug07:03:04

The word React just turns on my ignorant switch 😞

urbanslug07:03:11

I need to learn react

wei07:03:19

would this override existing handlers?

rauh07:03:34

@urbanslug: Just like JSX: The JSX compiler rewrites <div> into React.createElement("div", null). Sablono does the exact same thing

rauh07:03:40

@wei: Nope, unless they have the exact same function. Then it's replaced

rauh07:03:21

@urbanslug: It's noteworthy that this happens at compile time (so html is a macro) and it's not interpreted (like reagent).

rauh07:03:44

Well... kinda, unless it can't transform it at compile time, then it gets intrpeted as a fallback simple_smile

urbanslug07:03:25

rauh: I am new to cljs so I don’t know what JSX is either 😐

urbanslug07:03:52

@rauh: hmmm I think I’ll take some time off and understand the prerequisites.

rauh07:03:28

@urbanslug: Yeah, learning React is super easy and quick. It's worth it. You can learn it from CLJS though.

urbanslug07:03:18

@rauh: How though? I’m finding very little info on react from cljs they assume some level of knowledge of react.

urbanslug07:03:35

I can’t find a resource.

rauh07:03:58

Well you still read the JS stuff about it... You just try out your things in CLJS

urbanslug07:03:50

Oh I see yeah, that makes sense. simple_smile

wei07:03:27

here’s my original version for comparison: https://gist.github.com/yayitswei/c1efdce6bfa2fc16b548

wei07:03:18

@rauh: getting Uncaught AssertionError: Assertion failed: Listener can not be null trying out your solution on this line:

(goog.events/listen (array goog.events.EventType.MOUSEMOVE goog.events.EventType.KEYPRESS)
                    #(handler %))

rauh07:03:41

@wei: Your parens don't add up

rauh07:03:26

@wei: Where is target?

wei07:03:19

@rauh good point. misread your gist

wei07:03:22

works now, thanks!

danielgrosse08:03:36

When I use map to go over a nested structure, how can I prevent, that nil values are stored?

rauh09:03:49

@danielgrosse: keep should do that

danielgrosse10:03:05

I found a solution which uses postwalk

(clojure.walk/postwalk #(if (coll? %) (into (empty %) (remove nil? %)) %) (build-tree menu-data-structure))

danielgrosse10:03:57

Unfortunately it only works when I call it this way. When I use it inside a function and call the function with the same data, it doesn't remove the nils. How could this be?

danielgrosse10:03:48

(defn remove-nils 
[coll] 
(clojure.walk/postwalk #(if (coll? %) (into (empty %) (remove nil? %)) %) 
coll)

(remove-nils (build-tree menu-data-structure))

danielgrosse10:03:14

build-tree returns a map function which goes over a nested structure

danielgrosse10:03:21

It was a failure in my file. 😩

vinodg11:03:18

how to include external javascript file in reagent?

not-much-io11:03:26

@vinodg Isn't really a reagent specific question simple_smile . If you used something from cljsjs (http://cljsjs.github.io/) , then:

(ns my-ns
  (:require [cljsjs.js-lib]))
Otherwise, you can just include it in your html header, as without cljs. For both methods, to access the js libs stuff, use interop:
(js/my-lib-foo)

not-much-io11:03:05

@vinodg: If I understood "external javascript file" correctly.. Maybe I misunderstood?

vinodg11:03:04

@not-much-io: I have a javascript file containing code for generating a "captcha". now i have to include that file in clojurescript code

not-much-io11:03:47

@vinodg: If you are using reagent, then you have a regular html file, where reagent is mounted onto a div with id "app"? Example: https://github.com/Day8/re-frame-template/blob/master/src/leiningen/new/re_frame/resources/public/index.html Just add the usual js include tag there. And then you can use your lib with interop: (js/gen_captcha)

not-much-io11:03:58

@vinodg: What I mean by "usual js include":

<script src="js/captcha.js"></script>

rauh11:03:01

@vinodg: Do you want to 'on-demand' load the captcha library? Or are you asking how to call the functions provided by it?

vinodg11:03:32

i am getting the <script type="text/javascript" src="http://api.recaptcha.net/challenge?k=6Lcpy9YSAAAAAKPK5T8tdO5WbiRPkKENziunk0c2"></script> .now i have to include that in clojurescript

vinodg11:03:46

from server

not-much-io11:03:35

@vinodg: It should already be there, clojurescript is just compiled into js and thrown into your page, together with your other js. There is no extra step to include it.

not-much-io11:03:57

@vinodg: Try:

(.log js/console js/RecaptchaState)
Edit: Sorry, forgot to log the var.

vinodg11:03:49

@not-much-io: see when i make a jax request to the server , i will get "<script type="text/javascript" src="http://api.recaptcha.net/challenge?k=6Lcpy9YSAAAAAKPK5T8tdO5WbiRPkKENziunk0c2"></script>" from server . now ,I at clientside should include it in my hiccup code

not-much-io12:03:08

@vinodg Aaa, dynamically... This is the equivalent markup:

[:script {:type .. :src ..}]
So if you add it to your markup before you actually use functions from there, it should work? Maybe? 😄

slotkenov12:03:04

Anyone ever seen: Exception in thread "main" java.lang.RuntimeException: No dispatch macro for: =, compiling:(core.clj:39:1)

urbanslug12:03:28

Is there a reason a (go (while true (…)) would stop running quietly?

dm312:03:45

@slotkenov: do you have a stray #= somewhere in your code?

bronsa12:03:34

@slotkenov: #= is not a valid cljs reader macro

bronsa12:03:44

(you shouldn't use it in clojure either)

slotkenov12:03:49

@dm3 I can’t find any occurances of #= in my project

dm312:03:28

what are you doing to get that exception?

rauh12:03:23

@vinodg: (js/goog.dom.htmlToDocumentFragment "<script src=....></script>") then append with (goog.dom.appendChild js/document.body the-fragment) should work.

slotkenov12:03:25

@dm3: lein ring uberwar

slotkenov12:03:36

Has to do something with dependency versions I think

nidu12:03:53

@slotkenov: Had this issue recently with environ plugin from https://github.com/heroku/clojure-getting-started/blob/master/project.clj project. Fixed it by replacing it with string from official page.

dm312:03:02

@slotkenov, do you know what's in core.clj on line 39? simple_smile

dm312:03:43

looks like the datareaders aren't loaded properly

slotkenov12:03:57

I’m actually not sure which core.clj it means...

slotkenov12:03:17

I see environ in the stacktrace however

slotkenov12:03:42

@nidu: how do you mean you fixed the problem? What did you replace with a string?

nidu12:03:52

@slotkenov: not sure i remember how it fixed but first of all i replaced [environ/environ.lein "0.3.1"] with [lein-environ "1.0.2"]

slotkenov12:03:45

I’ve got environ and lein-environ

nidu12:03:52

@slotkenov: if you have aot compilation - try to disable it (see here https://github.com/technomancy/leiningen/issues/2096)

slotkenov13:03:22

@nidu: That looks like it might be the problem, I have :aot in my project.clj

slotkenov13:03:46

Can you specify a commit hash in stead of a version number in your project.clj?

wei14:03:49

what’s the advanced compilation-compatible way of writing this? (set! js/document.location "logout”)

majenful14:03:54

hello there

majenful14:03:11

I try to follow modern-cljs tutorial (boot version), but when I type « boot cljs », the console prints the compilation but I don’t have any new file. Any clue ?

lopalghost14:03:01

@wei: (aset js/document "location" "logout") should work

dhruv115:03:15

I keep getting this error in my browser’s console Uncaught Error: Assert failed: Could not find ReactDOMServer server(anonymous function) @ server.cljs?rel=1458656519107:12 dom.cljs?rel=1458656519142:13Uncaught Error: Assert failed: Could not find ReactDOM dom(anonymous function) @ dom.cljs?rel=1458656519142:13

dhruv115:03:49

I don’t know how to avoid it

dhruv115:03:54

can anyone help?

dnolen17:03:04

@wei that should probably be js/window.location ? - Google Closure has externs for standard browser things

yuris20:03:49

fkkmkmkefkekekekekm

anmonteiro21:03:46

I'm seeing certain protocol methods give an "undeclared Var" warning in advanced compilation, when I use them in a macro

anmonteiro21:03:03

has anyone seen this before?

zilvinasu21:03:27

I am using github API to search repos with cljs-http lib, the code for call looks like following: ` (http/get api-url {:with-credentials? false :basic-auth {:username “someuser" :password “somekey"} :query-params {:q params}}) `

zilvinasu21:03:38

Any ideas why does it send OPTIONS request before sending actual GET?

jr21:03:56

@zilvinask: CORS preflight request

zilvinasu21:03:12

jr: thanks, gonna read on that

anmonteiro21:03:28

@mfikes: tried to use the approach you describe here https://groups.google.com/d/msg/clojure/34luqPyg6L4/ksSrvXOiWdIJ without success

anmonteiro21:03:49

has something changed in the meantime?

mfikes21:03:35

@anmonteiro: Not that I’m aware of. You suspect a regression?

anmonteiro21:03:22

@mfikes: haven't investigated enough to suspect a regression

anmonteiro21:03:54

but using ^:export in a protocol method doesn't seem to solve my undeclared var warnings

mfikes21:03:46

Undeclared var is from the analyzer… I wouldn’t expect ^:export would affect that anyway.

mfikes21:03:20

There are some tickets related to needing to qualify protocol symbols when from another namespace...

anmonteiro21:03:05

I think this only happens when I call the method from a macro

anmonteiro22:03:42

yep, only happens when calling a protocol method inside a macro

anmonteiro22:03:53

and only in advanced compilation

anmonteiro22:03:16

@dnolen: maybe you have some insight into this? this is related to OM-643, and I've tracked it down to calling ident inside the defui macro

anmonteiro22:03:17

it seems that it only happens when calling a protocol method from the "same" namespace. In a macro

anmonteiro22:03:58

calling a protocol method from another namespace does not produce a compilation warning

mfikes22:03:59

@anmonteiro: If you are in native code for everything, no need to mess with ^:export, right?

anmonteiro22:03:44

@mfikes: I'm not sure I understand

dnolen22:03:06

@anmonteiro: would like to see a minimal example, non-Om - would greatly clarify the problem if there is one

anmonteiro22:03:40

let me try and create a minimal thing

mfikes22:03:42

Well, in that mailing list post you referenced, the point of using ^:export was so that foreign code (not-ClojureScript) could call the protocol method, even under :advanced

anmonteiro22:03:02

@mfikes: ah yes, you're right. This seems like a whole other issue

mfikes22:03:55

Yeah, no doubt you’ve found an issue. Wonder if it occurs in :none mode.

mfikes22:03:18

Oh, you already said, only :advanced. Nvm.

mfikes22:03:41

Yeah, a minimal repro simple_smile

anmonteiro22:03:46

working on it!

anmonteiro23:03:16

if I defrecord or deftype in the macro instead of defn the bug goes away, so I'm not entirely sure if this is a real issue or not

mfikes23:03:24

@anmonteiro: Curious if the bug persists if you drop the bug.core qualification here https://gist.github.com/anmonteiro/3a8fdc5ba085e3895254#file-bug-clj-L9

anmonteiro23:03:26

almost certain it does. confirming

mfikes23:03:21

@anmonteiro: Cool. Was worth eliminating, as there have been tickets surrounding that aspect.

mfikes23:03:02

@anmonteiro: If you macroexpand and see what is generated and the generated stuff looks legit, then maybe it really is a bug

anmonteiro23:03:04

@mfikes: macroexpansion:

(do (clojure.core/defn MyBug [])
    (cljs.core/specify! (. MyBug -prototype)
      Object
      (bar [this]
        (bug.core/bug this 3))
      (foo [this] "foo")))

mfikes23:03:08

I guess that looks legit. I’m not an expert on specify!. Especially if that code works in expanded form, then it sounds like a bug.

anmonteiro23:03:36

@mfikes: right, but this only happens in advanced compilation, so I'm not sure if there's something else I should be doing

ag23:03:48

hey guys, I’m new to cljs. can someone tell me if I’m doing anything wrong. I want to use third-party react component, for example this one: http://react-components.com/component/react-datepicker I got it via npm, now just adding this to project.clj won’t do, would it?

:foreign-libs [{:file "node_modules/react-datepicker/dist/react-datepicker.js"
                                :provides ["react-datepicker"]}]

ag23:03:12

I could of course just stick the file directly to the page and then use it, but I want to feed it to the compiler