Fork me on GitHub
#clojurescript
<
2015-11-01
>
zentrope01:11:02

Suppose you have a lot of namespaces, but want to have a single names space that refers to a few vars in those others. The idea is that users can just simple.ns/this and simple.ns/that rather than have to care about all those implementation namespaces.

zentrope01:11:14

How do you pull in those other vars?

zentrope01:11:30

(def MyThing #’other.ns/foo) doesn’t seem to work too well.

zentrope01:11:40

I bet it’s not working because I’m using defcomponent (quiescent) which is probably not creating the var I think I’m creating. Or something like that.

zentrope02:11:20

There’s also that (repeatedly (identity #’something.or/other)) I’ve seen somewhere … can’t remember what it was.

mfikes02:11:11

@zentrope: One note: With the way you have MyThing defined, it is bound to the var, so you’d need to use @MyThing to get to the value of other.ns/foo.

zentrope02:11:34

Oh, hm. That sounds familiar.

mfikes02:11:40

You could instead (def MyThing other.ns/foo) to bind to the value

zentrope02:11:17

Tried that. Seems to blow up my UI. Going to try to figure out how to debug it.

zentrope02:11:57

Okay, it helps to (:require [other.ns :as ns]) in the “summary” namespace.

mfikes02:11:27

True that simple_smile

jannis02:11:00

Is there a reason (partial ...) and #(some-fun ...) are not executed in -> and ->? Example: (-> "World" (partial println "Hello"))

jannis02:11:57

I keep on writing things like (-> "World" ((partial println "Hello"))) and (-> "World" (#(println "Hello" %))). Either my approach is bad/wrong or I'm missing something. (-> "World" println) works and my thinking is that println is no more or less a function than (partial println "Hello") or #(println "Hello" %) should be.

zentrope02:11:30

This works for me: (->> "world" ((partial println) "hello”))

mfikes02:11:44

@jannis: Try (macroexpand-1 '(-> "World" (partial println "Hello")))

zentrope02:11:34

Ah. Because -> is a macro, (partial println “hello”) is not evaluated before the macro rewrites it as (partial “world” println “hello”).

mfikes02:11:37

@jannis: I was initially confused by -> in what I suspect is also confusing to you. It is not passing values to subsequent functions for execution. It is much simpler and just rearranging the code.

mfikes02:11:53

Right. -> doesn’t produce ((partial println "Hello") "World”)

jannis02:11:25

Oh, I see.

jannis02:11:36

@mfikes: I was indeed thinking like that.

mfikes02:11:56

In a sense, -> is simpler than you thought. simple_smile It is just sugar; rearranging things.

jannis02:11:44

How come the result of (-> "Hello" println) and (-> "Hello" (println)) is the same?

mfikes02:11:03

Read the docstring. It mentions that case exactly.

jannis02:11:52

Sweet, I get it.

jannis02:11:05

It turns forms into lists if they aren't and then basically inserts one form into the next to build the final expression.

mfikes02:11:43

Yep, and then evaluation occurs after all of the threading is complete.

jannis02:11:38

Yeah. Ok, I get it. And it does fun stuff with anonymous functions, like (fn* "World" [] (println "Hello")) 😄

jannis02:11:18

Which makes sense but is not very useful.

jannis02:11:37

@zentrope: @mfikes: Thanks for the explanation. I've been using Clojure/CLJS for a while now but haven't thought much about how it does things like this. simple_smile

nowprovision05:11:49

this style on ns :requires seems pretty neat https://github.com/danielsz/system-advanced-example/blob/master/src/example/systems.clj#L4 but it seems clojurescript doesn't this ?

thheller08:11:57

@nowprovision: correct, that is not supported

amacdougall14:11:56

I'm curious if anyone has already written an example of connecting an Om Next app with a boring REST API. Part of the motivation of Om Next is that REST is bad—but REST is mad entrenched. I think understand how to go about it, but if someone else has already written it, why reinvent the wheel? (...weird to think of REST as "legacy" in a world that still has SOAP APIs. I guess everything is contextual.)

akiva15:11:49

Might want to bring your question to #C06DT2YSY.

darwin15:11:47

is there any tool which would show me where exactly I have a circular dependency? I did pretty large refactoring and now getting StackOverflow errors from analyzer. I know it is a circular dependency but I’m sick of trying to comment out individual requires to pinpoint the problem.

pesterhazy16:11:16

@darwin: if there is, I'd like to know it

pesterhazy16:11:29

I've been in the same situation

darwin16:11:36

it took me 30 minutes to figure out, that I was requiring my own namespace, (:require-macros [my.ns :refer …]) was fine, but I replaced it with (:require [my.ns :refer-macros …]) - it makes sense, but it was hard to find this needle in this change set: https://github.com/darwin/plastic/commit/c27151a0ed07b4faade721dc53f5241156cb6b7c

darwin16:11:16

yeah, doing require my.ns inside my.ns is a stupid thing to do 😉

pesterhazy16:11:30

better error messages would help here

thheller17:11:58

@darwin how much are you liking all those source directories?

thheller17:11:22

looks pretty painful to me simple_smile

darwin17:11:36

@thheller: I’m still looking for good layout, the problem was that part of my sources should go into a web worker, part into main js context, part is shared, and meld is going to be a separate library one day, dev is included only in dev builds, so I wanted/needed to keep them separated because of how cljsbuild works

darwin17:11:49

and there are also devcards, which have another story

thheller17:11:52

yeah I understand why you do it

thheller17:11:01

but what if I told you that you don't have to 😉

darwin17:11:29

yep, I could use your tool simple_smile

darwin17:11:33

shadow build? simple_smile

thheller17:11:12

trying to write docs .. but looking for good examples that aren't my closed source projects from work 😛

thheller17:11:44

if you are interested I'd create a fork with a shadow-build config and you can decide whether you want to use it or not

darwin17:11:04

thanks for the offer, how does it play with figwheel?

thheller17:11:23

it doesn't .. replaces it in fact

thheller17:11:36

but you get the same live-reload and REPL

thheller17:11:07

I'm not yet clear on devcards though, it seems to require figwheel which I do not quite understand why

darwin17:11:58

hmm, I’m a bit afraid I would run into other problems with figwheel and maybe other tools, you know leiningen + cljsbuild path is pretty popular and bhauman has been very helpful in resolving any issues

darwin17:11:51

it is not just about live-reloading, also his “HUD” system displaying errors/warnings, ability to watch multiple cljsbuild targets, etc.

thheller17:11:02

yeah, totally understand that.

darwin17:11:41

and I can live with this directory layout, it is not that bad, it just forced me to do it this way, but it works

thheller17:11:42

yeah the project looks massive

darwin17:11:54

worse is, that is forced me to rewrite some libraries 😉 first I ditched servant, then rewrote re-frame and now thinking about writing my own reagent 😉

thheller17:11:02

hehe I know the feeling

thheller17:11:59

I have some support for web-workers and shadow-build that makes packaging them quite easy, even with code sharing between the main process and worker

thheller17:11:12

via automatic importScripts generation

thheller17:11:39

so servant would probably be obsolete 😉

darwin17:11:31

I’m not sure if web-workers knowledge should be part build tooling, the tooling should be just flexible enough to define some hooks for including raw javascript / foreign libs

thheller17:11:06

well ... it might not be in your case since you are packaging an "app" and filesize doesn't matter too much

darwin17:11:10

in my case setup for dev build and final optimized build will be quite different, I assume I will rely on google closure modules for splitting

thheller17:11:23

in the browser it is very relevant to "share" code

thheller17:11:43

so the user doesn't download the 100kb cljs.core once for the browser and then once for each worker

darwin17:11:17

I see, this should be solved by closure modules, not cherry-picking files

thheller17:11:57

yes definitely .. workers usually share a lot of code with the normal browser window

thheller17:11:09

if not all ..

thheller17:11:02

downloading things twice only because a few lines changed is not great

darwin17:11:10

yeah, in that case modules are also a win, all shared code goes into one js file which gets cached

thheller17:11:14

but more relevant in the browser ... not so much in apps

thheller17:11:33

anyways .. need to get some work done to catch up with figwheel 😉

darwin17:11:07

have fun! 👍

anmonteiro17:11:36

@mfikes: first time trying out CLJS + RN, wondering how to perform debugging

anmonteiro17:11:24

(or anyone else in the channel simple_smile )

mfikes17:11:14

Otherwise it is an open issue listed on http://cljsrn.org/roadmap.html

anmonteiro17:11:03

I'm also very new to XCode; is there a way to see where React Native spits out JS errors?

anmonteiro17:11:15

or this would only happen if debugging was possible?

mfikes17:11:51

React Native has its red screen mechanism

anmonteiro17:11:21

I haven't been getting that

anmonteiro17:11:11

it just doesn't progress to my CLJS code whenever there's an error

thheller17:11:27

someone here aware of a cljs.test "env" that visualizes the output in the browser instead of just the console?

thheller17:11:47

thinking about hooking things up to the goog.test stuff

thheller17:11:56

just wondering if someone has done that already

pesterhazy18:11:43

@anmonteiro: are you not seeing anything in the Xcode "debug output" window?

anmonteiro18:11:00

nope, just the target output shows

anmonteiro18:11:28

do you mean the xcode console?

anmonteiro18:11:57

i can log from my code and see it show there

anmonteiro18:11:03

but not react's errors

pesterhazy18:11:55

not sure then

jaju18:11:59

Hi. This is regarding cljsjs - If I depend on a library that provides CSS alongside the JS, do I need to download the CSS by other means and include in my HTML?

jaju18:11:13

I see that the JAR has the CSS though - but I can’t find any instructions on how I can use that

juhoteperi18:11:21

@jaju: You can use ring resource middleware or compojure resources route to serve the files

jaju18:11:50

@juhoteperi: I’m in an electron-shell environment. It’s a standalone app.

juhoteperi18:11:06

I have no idea how electron works but you can access the files with

jaju18:11:21

But that may be useful information for me in some other context - I will keep that in mind when I need to serve from a web server. Thanks. Any docs which talk about configuring for serving?

jaju18:11:26

There’s no java in electron. Plain JS (nodejs). No web-server. I need to be able to include the CSS in an HTML file read from the filesystem.

juhoteperi18:11:34

I don't think there are docs about serving the files. Some example projects probably have examples.

juhoteperi18:11:34

You probably need to use your build tool to copy files from classpath to filesystem or something.

jaju18:11:01

Kind of last resort. I could use bower to get those files - easier than getting leiningen to copy maybe? But that would mean dependencies in two places, which doesn’t feel clean...

juhoteperi18:11:03

You could write a short Clojure file which copies files from classpath to filesystem and run it with lein trampoline run -m clojure.main scripts/copy.clj

jaju18:11:04

Thanks @juhoteperi. I’ll keep that as an option. But I think there must be something about the cljsjs packaging that’s not known to me yet, which makes this more straightforward than this. If I don’t find that in - say - a day, copying via a script as you mention or a bower dependency is what I will need to resort to.

dnolen19:11:12

@jaju JARs are just zips

dnolen19:11:04

you would need to write some helper functions to get at their contents, index them etc. - I wouldn’t be surprised if someone hasn’t already done something like this for Node.js

samumbach23:11:30

is anyone aware if there's already a CLJS issue related to this "Use of undeclared Var warning.core/clj-nil" warning? (see also: https://github.com/r0man/sablono/issues/33)

samumbach23:11:27

I spent some time looking into this (since I'm hitting this warning in another codebase) and I think there's something up; I started trying to characterize it here: https://github.com/sumbach/type-leak-test/tree/unit-tests