Fork me on GitHub
#clojurescript
<
2015-10-29
>
dvcrn06:10:03

little namespacing question... src/cljs/ui/electron/menu.cljs looks like this:

(ns 
  (:require [ui.parser :as parser]))
src/cljs/ui/parser.cljs like this:
(ns ui.parser)
cljsbuild target like this:
{:id "ui:dev"
                        :figwheel true
                        :source-paths ["src/cljs/ui" "src/cljs/dev"]
                        :incremental true
                        :jar true
                        :assert true
                        :compiler {:main "ui.core"
                                   :output-to "app/js/front.js"
                                   :externs ["app/externs.js"]
                                   :warnings true
                                   :elide-asserts true

                                   :output-dir "app/js/out-frontend"
                                   :asset-path "js/out-frontend"
                                   :optimizations :none
                                   :pretty-print true
                                   :output-wrapper true}}
yet every time I try to compile things, I get a error inside menu.cljs:
Caused by: clojure.lang.ExceptionInfo: No such namespace: ui.parser, could not locate ui/parser.cljs, ui/parser.cljc, or Closure namespace "ui.parser"

dvcrn06:10:53

ui/parser.cljs is clearly there. How can I resolve this problem?

dvcrn07:10:46

everything under src/cljs/ui/ is one cljsbuild target. There are other folders like src/cljs/backend/ as well, but they have separate builds

martinklepsch07:10:00

@dvcrn: if source paths is "src" it will look for the namespace "my.app" in "src/my/app.cljs"

dvcrn07:10:31

@martinklepsch: ohh... so I'm one level too high? For that to make sense I have to put my things into src/cljs/ui/ui?

martinklepsch07:10:36

@dvcrn: yes I think that would do it

dvcrn07:10:11

hmm ok let me try that

dvcrn07:10:37

each of these compile into a different .js file with the exception being dev/. That gets merged into ui/

martinklepsch07:10:20

Probably a source did for each of them

dvcrn07:10:47

that's actually what I had before lol I thought it would be better to put it all into one src/

dvcrn07:10:28

guess I'll roll that change back then

ul09:10:54

what is the best way to declare union-type like schema in prismatic schema? either marked as deprecated in favor of cond-pre, and cond-pre is marked as experimental in its turn

hmadelaine10:10:28

Hi @ul, I had the same struggle, I use cond-pre

ul10:10:17

@hmadelaine: thank you! I tried this, seems to be working

hmadelaine10:10:04

@ul the documentation is not very clear on that subject.

ul10:10:29

sadly reported messages too =( just tried to make one of my functions with schema definition, got long error about schema data mismatch, but not sure for what exact reason

ul10:10:42

but i think i need some time to get used

hmadelaine11:10:37

@ul sometimes I had great difficulties to understand why Schema is yelling at me 😉

ul11:10:10

i want to try to do some refactor of my codebase programmatically, what is the best library for walking and changing code? https://github.com/xsc/rewrite-clj ?

ul11:10:12

does it support cljs files?

chedgren11:10:24

ul: What is the difference between cljs and clj files that you see would make a difference in support for rewrite-clj?

ul11:10:01

i just not sure about size of domain where it is working. if it just eats edn and doesn't trie to understand it, everything should be okay

chedgren11:10:09

yeah, that's how i see it too

chedgren11:10:17

and all clojurescript is clojure

chedgren11:10:26

but not all clojure is clojurescript

ul11:10:47

hmmm... cljs.core has some funcs that are not in clojure.core and differences of interop, if you mean smth like that

ul11:10:05

from the syntax point of view they are just the same, not one subset of another

chedgren11:10:22

yeah, or as the docs have it: ClojureScript is the same (at a Lisp level) as Clojure except for the following: no runtime evaluation no runtime compilation

ebaxt12:10:24

So I’ve started my first ClojureScript project 😱 It’s working (sort of), but I’m struggling to find a good workflow. Server-side I have a standard ring app with http-kit I’ve also set up reloaded.repl. Client side I use ClojureScript and chord to communicate with the server. I’ve also added figwheel. Everything seems to work fine, except things crash when I run reloaded.repl/reset server side. It causes my browser to hang (I can’t reload the page or close the browser). Before I spend a lot of time debugging, I figured I would ask here if there are any obvious things I might have done wrong given my setup?

ricardo13:10:09

@bensu: I finally got a chance to start using doo. Pretty neat!

dnolen13:10:28

@chedgren: that’s not even quite true, runtime evaluation / compilation is optional - just not default.

chedgren13:10:07

@dnolen: Is it silly to think of cljs as a subset of clojure?

dnolen13:10:37

@chedgren: thanks for pointing that out, I removed those outdated bits just now

magnars13:10:32

@ebaxt: sounds like just the setup I use in http://parensofthedead.com - have you looked at differences between that and your code? You don't have to try to catch everything via the videos, the code is here: https://github.com/magnars/parens-of-the-dead

ebaxt13:10:43

@magnars: Thanks, I used your project as a starting point simple_smile I managed to isolate the problem to chord, and eventually managed to prevent Chrome from freezing up by handling closed channels properly.

dnolen13:10:09

@chedgren: and to answer your actual question - no it’s reasonable to think of ClojureScript as a subset of Clojure with affordances for the JavaScript runtime instead of Java

magnars13:10:20

ah, the good old when-let around a recur in a go-loop simple_smile

chedgren13:10:21

dnolen: ty, it's nice to hear that my model of how things work isn't off

richiardiandrea14:10:17

have anyone had luck including [mvxcvi/puget "0.9.2"] in a ClojureScript project? It throws a no namespace puget.printer exception at me

dm315:10:08

do you have whidbey or ultra on the classpath by any chance?

richiardiandrea15:10:55

ah, I have ultra...but a colleague of mine has empty profile.clj

dm315:10:06

had the same problem yesterday when trying to use fipp

richiardiandrea15:10:08

no but I wanted to include it in a project, to use programmatically printer.cprint, can it be min-lein-version?

dm315:10:07

has to be 2.5.2 to handle cljc I think

richiardiandrea15:10:41

I am on 2.5.3 but maybe something goes hairy

dm315:10:23

well, if ultra loads first then old puget gets on the classpath, no?

richiardiandrea15:10:00

true, will try, but this does not explain the behaviour with empty profile

dm315:10:28

sure, no conflicts in lein deps :tree?

richiardiandrea15:10:25

i even tried puget 0.8.1

pandeiro16:10:07

ISO: approaches to serializing/deserializing/sanitizing JSON data with keys like {"This Is Gonna Hurt": true}.

pandeiro16:10:49

ie, Does this mean I have to abandon (js->clj json-response :keywordize-keys true) altogether?

donaldball16:10:36

(keyword “This Is Gonna Hurt”) does yield a keyword value, though it’s technically not a valid keyword

donaldball16:10:16

Stuart has claimed the behavior of the keyword fn hereby is unspecified, IIRC

donaldball16:10:17

If you have no guarantee your json keys aren’t valid keywords, I’d skip the nicety of keywordize-keys myself

donaldball16:10:04

But I’m sorry, you’re talking about cljs, everything I’ve just said may be complete lies in this world, apologies.

pandeiro16:10:30

@donaldball: No, useful and valid observations. Giving up keywords is painful though. Still mulling it over.

donaldball16:10:34

iirc cheshire allows you to supply a fn governing the transformation of json keys

pandeiro16:10:24

@donaldball: right, as does clojure.data.json/read...

pandeiro16:10:23

In this frontend case, I think the keyword conversion is actually baked in to the HTTP lib (cljs-http)

pandeiro16:10:20

@dnolen: Do you know if using transit would somehow circumvent this issue? Like does it "fix" keys with spaces automatically somehow?

dnolen16:10:33

if you want my honest opinion, keywordizing string keys is just more trouble than it is worth

dnolen16:10:44

and no transit doesn’t solve that problem

pandeiro16:10:15

OK, thanks for the honest opinion. Looks like a consensus.

pandeiro16:10:03

Unfortunately it's the default (and I think non-configurable) when using cljs-http to talk JSON

dnolen16:10:14

sounds broken to me

dnolen16:10:37

if that’s actually the case

dnolen16:10:13

@pandeiro: I took a look at cljs-http, it’s not hard to fix this, write your own 5-10 lines of middlware

pandeiro16:10:47

@dnolen: Cheers; I'm trying to understand if there's an API for modifying middleware or if I'm supposed to just create a new replacement request with the ones I want... Guessing the latter

pandeiro16:10:39

...So it's also replacing every cljs-http/get, put, post etc in the codebase...

pandeiro16:10:01

I can't somehow overwrite cljs-http.client/request to what I want, right?

dnolen16:10:36

sorry can’t help more right now

dnolen16:10:45

but there’s not that much code involved here

dnolen16:10:23

it may be the case that it’s more work than I thought, I don’t have time to read that code further

pandeiro16:10:00

No worries, appreciate it. It is the case I'm pretty sure, so I'm creating an issue to see if @r0man is interested in maybe streamlining that use-case.

mbertheau17:10:12

Is there a reason other than "noone got around to it", that goog.net.IframeIo is missing from ?

pandeiro18:10:17

@mbertheau: I was just looking at that these days (the Closure lib ns, not the http://clojure.browser.net)

pandeiro18:10:30

I couldn't figure out exactly what it does, but I think I like it

dnolen18:10:13

@mbertheau: is really more of an implementation detail namespace

dnolen18:10:21

unlikely to add anything more to that

mbertheau19:10:32

@dnolen: What is meant by that exactly? It shouldn't be used by applications usually?

dnolen19:10:48

it should not

dnolen19:10:52

it’s not there for generic use at all

dnolen19:10:59

just to support browser REPL

chrisn20:10:29

Is there a clojurescript translation of the javascript require function? I am running tests in phantom and I would like to do this:

var system = require('system');
var env = system.env;

Object.keys(env).forEach(function(key) {
  console.log(key + '=' + env[key]);
});
I can also just do it in javascript if I have to.

dot_treo20:10:01

@chrisn, I guess js/require should work

chrisn20:10:28

Can't find variable: require

roberto20:10:56

node/require

chrisn20:10:26

can't find variable: node.

roberto20:10:44

you need (:require [cljs.nodejs :as node])

spinningtopsofdoom20:10:48

phantom doesn't have require you have to use injectJs http://phantomjs.org/api/webpage/method/inject-js.html.

roberto20:10:53

then you can do node/require

roberto20:10:40

at least that is what worked for me when I first tried using cljs with node about a year ago.

chrisn20:10:07

I am not using node at all.

chrisn20:10:22

I am using phatom and they state you can get environment variables like this.

chrisn20:10:37

All I am doing is using doo, phantom and some test code.

roberto20:10:55

well, require is a nodejs construct.

spinningtopsofdoom20:10:56

@chrisn: You're looking to use some phantom libraries correct?

chrisn20:10:03

No, I am using phantomjs

chrisn20:10:15

the headless js harness.

chrisn20:10:27

It has require implemented.

chrisn20:10:43

That script above, if executed without any further parameters runs.

chrisn20:10:00

But yet

(js/require "system")
fails

chrisn20:10:07

If I do it in clojurescript.

spinningtopsofdoom20:10:44

Okay I think I found how to do what you need. The cljs.nodejs namespace has this (def require (js* "require")) which defines require as a statement. js/require treats require as a global javascript object instead of a statement. once you def require you should be able to use it like (require "event")

spinningtopsofdoom20:10:37

so the top two statements of your example would be

(def require (js* "require"))
(def system (require "system"))
(def env (.-env system))

spinningtopsofdoom20:10:09

let me know if that works

dot_treo21:10:13

looking at the generated output @spinningtopsofdoom solution as well as a simple js/require should have worked

chrisn21:10:26

same issue.

chrisn21:10:37

can't find reference.

dot_treo21:10:00

take a look at the generated code

pandeiro21:10:14

is it possible to pprint to the cljs repl?

pandeiro21:10:20

(set! print-fn println) ?

dnolen21:10:34

@pandeiro: yes you could do something like that

pandeiro21:10:40

ah yeah works but the pprint fn is blowing the stack

pandeiro21:10:48

but is there another way?

dnolen21:10:23

can’t think of anything

chrisn21:10:36

@bensu, does doo run phantom in a mode that removes some of its built-in libraries?

bensu21:10:15

@chrisn: no. where do you want to run the code? in the script or in the browser?

bensu21:10:24

those are two different environments

bensu21:10:47

the script has access to all the libraries, like system and page

bensu21:10:02

the browser has only access to what you include in your cljsbuild

chrisn21:10:15

Yes, the phantom test script.

chrisn21:10:19

Is where this is relevant.

bensu21:10:42

right, if you want to run your own phantom script, doo is not going to help you

bensu21:10:56

doo provides a script to run cljs.test

chrisn21:10:27

Yes. The real problem I am fighting is that I need an environment variable from inside my cljs script.

chrisn21:10:52

Phantomjs provides access via the method I posted way earlier but I cannot figure out how to get to that method while testing.

bensu21:10:16

well, phantom provides that in the script not in the browser

bensu21:10:43

whatever the cljs compiler produces is run in the browser

bensu21:10:53

so, using those functions is not going to help you

bensu21:10:02

this is a known/unresolved issue

bensu21:10:10

do you use environ?

chrisn21:10:43

Wait, I only need these during unit testing. I don't need them when I am in the browser because the server sets these up.

chrisn21:10:22

No, the real answer is that we define this code in handler.clj and send it over during runtime but during test time they simply exist in the environment.

chrisn21:10:32

With the old cemerick testing system we could provide javascript to execute before executing the main test script and this allowed us to set a js variable when testing to this environment variable's value.

bensu21:10:57

right, var env = {}

bensu21:10:21

when I say "the browser" I mean the WebKit instance provided by phantom for your tests

chrisn21:10:17

So then phantom is run in basically two different modes? If I provide a js file it runs it in the script but if it gets an html page it runs it in the browser?

bensu21:10:36

phantom always runs two different modes

chrisn21:10:44

oh, sorry, I definitely didn't realize that.

bensu21:10:17

so, you first feed it a js script which looks mostly like node.js code

bensu21:10:24

that is "the script"

bensu21:10:01

in that script you can ask to open a webpage and evaluate code. that's when phantom makes a webkit instance and runs your code sandboxed there

bensu21:10:13

that is what I'm calling "the browser"

bensu21:10:29

they are two different scopes

chrisn21:10:09

Hmm, Can I pass information from the first scope into the second while still using the doo framework or does that mean I am completely off into my own non-doo universe?

bensu21:10:47

can you include the information in the cljs build at compile time?

chrisn21:10:31

Great question, if I can define arbitrary javascript to include into the cljsbuild then yes.

chrisn21:10:12

Or you mean wrap leiningen with a build script?

bensu21:10:29

does that arbitrary javascript need access to your environment variables (aka is it node.js code)? then no

bensu21:10:23

you can add an arbitrary script to run in the browser through foreign-libs

bensu21:10:42

but that won't have acccess to the environment, because the browser doesn't

chrisn21:10:45

We had something like this before (in project.clj):

~(str "window.base_url='" (System/getenv "CATALOG_URL") "';")

bensu21:10:57

there we go

bensu21:10:32

@martinklepsch was kind enough to add those to the compiler.

bensu21:10:59

now you can do {"goog.base_url" ~(System/getenv "CATALOG_URL")}

bensu21:10:46

then you can use goog.base_url from insde the cljs code.

chrisn21:10:08

phew. This is a really nasty problem actually.

chrisn21:10:20

you saved me yet again, @bensu...

bensu21:10:13

from this side, it was harder to communicate than to solve. The compiler has matured a lot in the last year

bensu21:10:49

most unavoidable hacks can now be properly solved with all the new features

bensu21:10:10

did it work?

chrisn21:10:52

(println (aget goog "base_url"))
did not but I get that is just not how you get to the goog stuff

chrisn22:10:55

OK, I either need a js library just to define that closure variable or I need to hijack an existing closure variable.

bensu22:10:07

you go to your namespace and define a default using that macro (macro? not sure)

bensu22:10:04

and then use it as you would normally do, then at compile time, if the compiler finds it under :closure-defines it will overwrite it with that value

chrisn22:10:55

This works:

:closure-defines {'style.test/base_url ~(System/getenv "CATALOG_URL")}
combined with:
(goog-define base_url "")

kenny22:10:13

Does anyone know how do to use js typeof in cljs?

chrisn22:10:11

OK, now lein doo phantom once works but lein install doesn't because it doesn't find the doo namespaces. I really want the clojurescript compiler to never use the test configuration except during lein doo phantom once.

kenny22:10:35

@bensu: Sort of.. I need to check if the type of a property is a function though. Not sure that would help in this case.

chrisn22:10:29

Turns out of you use ids then this happens naturally.

bensu22:10:46

@kenny: maybe this (fn? (gobj/get your-obj "your-property"))?

kenny22:10:09

Yeah that's it simple_smile

bensu22:10:41

@chris: so it's solved? there are three things to do about that:

bensu22:10:05

a) make sure your other builds don't see the runner file which calls doo

bensu22:10:17

b) include doo as a dependency and not just a plugin

bensu22:10:32

c) use ids simple_smile

bensu22:10:18

in any case, @richiardiandrea has opened an issue to use doo alongside figwheel, which is close (running it in other build contexts)

richiardiandrea22:10:09

yes in my case I had to specify the doo runner in another folder:

{:id "test"
 :source-paths ["src/cljs" "test/cljs" "test/doo"]
 :compiler {:main launcher.runner
 :output-to
 :pretty-print false}}