Fork me on GitHub
#clojurescript
<
2015-07-02
>
chicoxyzzy00:07:45

oops.. now I did ctrl-c in REPL and now even rlwrap java -cp cljs.jar:src clojure.main repl.clj doesn’t work

chicoxyzzy00:07:13

Exception in thread "main" java.io.FileNotFoundException: Could not locate clojure/browser/repl__init.class or clojure/browser/repl.clj on classpath., compiling:(/Users/Chico/Projects/om-test/repl.clj:1:1)

dnolen00:07:32

chicoxyzzy: double check that your cljs.jar is an ~18mb file, common mistake to download the wrong thing

dnolen00:07:26

@chicoxyzzy: otherwise make sure you don’t have a global classpath setup with some version of Clojure on it

chicoxyzzy00:07:00

I didn’t change it anyhow when completing previous steps of tutorial and it looks fine 19842263 Jul 1 22:28 cljs.jar

dnolen00:07:21

@chicoxyzzy: seems very weird, but the error says different

roberto00:07:24

yeah, one of the main features of clojure/clojurescript that has kept me happy is the community. There is a lot of mutual respect between library authors and no feuding, compared to other communities.

dnolen00:07:57

@chicoxyzzy: you will only get that error if the classpath is wrong, or somehow the wrong version of Clojure is getting loaded

dnolen00:07:08

the only two possibilities really.

dnolen00:07:48

@chicoxyzzy: and reading back - namespaces map to Java packages more or less and those must match the classpath

dnolen00:07:00

no picking names that don’t match the directory structure

chicoxyzzy00:07:48

ok thank you. I’ll try to fix my issue and change my namespace to om-test.core

dnolen00:07:22

directory structure needs to be src/om_test/core.cljs, dashes become underscores

domkm00:07:40

CLJS compiler question: When it analyzes an ns declaration, does it begin emitting JS immediately or does that occur after the entire file has been analyzed?

chicoxyzzy00:07:49

cool. just created new project from scratch and all works fine now. than you @dnolen

chicoxyzzy01:07:03

https://github.com/clojure/clojurescript/wiki/Rationale#javascript-engines-gain-power I think we should add some info about forthcoming Web Assembly there simple_smile

mfikes02:07:00

(I think the answer is “right away,” depending on what you are really after.)

domkm02:07:33

@mfikes: Ah, interesting. Thank you.

domkm02:07:03

@mfikes: I’d like to write a macro that can be used from cljs to alter the current namespace. It seems like that might not be possible or might be too prone to breakage by compiler changes.

mfikes02:07:08

@domkm: ns is just a special form. It can be used in the middle of a file, if that's what you are thinking.

domkm02:07:08

@mfikes: Hmm, I thought ns was a macro. Is it a special form in cljs?

domkm02:07:22

@mfikes: I’d like to be able to alter a cljs namespace in a similar way to how potemkin can import-vars. I think I have it mostly worked out except for namespace alternation because cljs doesn’t have require.

mfikes02:07:58

@domkm: If you write a macro that involves ns, I suppose you'd have to be sure it comes back into ClojureScript after expansion.

danielcompton02:07:37

@domkm are you looking just to import vars like potemkin? Or something more?

domkm02:07:08

@danielcompton: Yes, import vars

mfikes02:07:14

@domkm: ns is a macro in Clojure, but a special form in ClojureScript.

domkm02:07:45

@mfikes: Interesting! I didn’t know. simple_smile

domkm02:07:57

Thanks. Unfortunately that just defines new vars which means that they have the wrong metadata. It also doesn’t work for macros.

danielcompton02:07:29

Ah rats, I hadn’t tried it yet

mfikes02:07:48

@domkm: (doc ns) will work in the next release. A preview of the output (showing it is a special form) is in http://dev.clojure.org/jira/browse/CLJS-1307

clojuregeek03:07:07

question on using cljs-ajax if someone has time ..

clojuregeek03:07:11

i have a liberator delivering a json api (above) and I am trying to make a ajax get call to load it into an atom (for looking at in figwheel repl) and printing to log …

clojuregeek03:07:10

i I load the page in the browser.. in figwheel repl I run (get-data) and this is the output

Figwheel: trying to open cljs reload socket
utils.cljs:40 Figwheel: socket connection established
ioc_helpers.cljs:41 Uncaught Error: No protocol method ReadPort.take! defined for type null: 
xhrio.js:561 XHR finished loading: GET "”.

clojuregeek03:07:27

i see in the network requests it accesses the url and response is data

jwm03:07:24

are you using lighttable

clojuregeek03:07:02

i am using emacs

jwm03:07:42

sorry missed the screencast link ( I usually do) heh

clojuregeek03:07:47

i look at the network tab and see my json data is Content-Type:text/plain;charset=UTF-8 .. maybe that has something to do with it ..

danielcompton03:07:49

@clojuregeek: looks like something to do with core.async

danielcompton03:07:09

ioc_helpers.cljs is a core.async file

clojuregeek03:07:40

i’m not using core.async for loading the data

danielcompton03:07:14

cljs-ajax is though

danielcompton03:07:12

do you know where exactly the error is thrown? Inside get-data, or inside handle-response?

clojuregeek03:07:03

let try again, i had typo in my handle function.. i’ve been trying different versions

clojuregeek03:07:03

hm got something back..

clojuregeek03:07:56

ok i think i’m getting back a string I need to parse to json.

danielcompton03:07:18

@clojuregeek: cljs-ajax has some helpers to do this for you

clojuregeek03:07:15

oh so dont need cheshire ?

clojuregeek03:07:10

ah that works simple_smile

clojuregeek04:07:03

ok thanks so much.. i better get to bed now before i get in trouble with hubby

malcolmsparks09:07:38

Last night I converted bidi from cljx to cljc, following the 1.7 announcement. However, I'm struggling to persuade lein to pick up the .cljc files in testing - is there an approach to testing that people are using that is working for them? Could really use some help here

danielcompton10:07:48

@malcolmsparks: I think there's some open issues around that, though if you pass particular files/namespaces (can't remember which) they'll be tested

danielcompton10:07:17

To lein test that is

slipset13:07:25

I have a cljs project which was set up with chestnut

slipset13:07:31

When I deploy to heroku with :optimizations advanced, it fails with cannot call .. on undefined,

slipset13:07:45

but it does work with :optimizations :whitespace

slipset13:07:28

which again calls (why, I don't know) goog.string.format.demuxes_["f"]

dnolen13:07:28

@slipset sounds like you're using a library with a bug. You need to find the source that makes that invocation.

slipset13:07:56

From looking at the code, it seems as if it is the js reader thingy which is causing me problems, since I'm passing js-opts to an om-component,

slipset13:07:39

The value of the key :now will be a float, which I guess has to be stringified so it can be passed to javascript.

dnolen13:07:18

What js reader thingy?

slipset13:07:21

I'm pushing a commit with :optimization :advanced right now, so I can give more exact info

dnolen13:07:50

Om doesn't use goog.string.format nor does ClojureScript

slipset13:07:32

in om, when you have a component you pass a first argument which becomes the attributes of the html-element, right?

slipset13:07:47

sorry, not component

slipset13:07:19

the thing that is nil here: (dom/p nil (:text data))

dnolen13:07:54

What you are talking about now seems unrelated to your bug

dnolen13:07:29

You said the error shows a call to format. You need find what code calls format. Nothing else is relevant really.

slipset13:07:49

Ok, Seems like the error is slightly different today than it was last night.

slipset13:07:03

I'll have to continue debugging, thanks!

Lambda/Sierra15:07:52

Using dependencies from http://cljsjs.github.io/ … Is there anything else you have to do after adding the dependency to project.clj and :require 'ing the namespace in a .cljs file?

crisptrutski15:07:25

@stuartsierra: nope, that should be all

crisptrutski15:07:05

perhaps an issue with the packaging on the cljsjs artifact? externs issue?

crisptrutski15:07:14

@martinklepsch: looks like your boilerplate metadata is showing 😉

Lambda/Sierra15:07:07

Specifically, loading cljsjs.d3 causes "Uncaught SyntaxError: Unexpected token ILLEGAL" in the JavaScript Console. I know this is an issue with D3 in general — the JavaScript sources use UTF-8 characters.

Lambda/Sierra15:07:27

The recommended solution is to make sure d3.js is sent to the browser with UTF-8 encoding.

Lambda/Sierra15:07:49

Figwheel is sending the JavaScript to the browser.

bhauman15:07:20

stuartsierra: Just a stab in the dark, Are you using the <meta charset="UTF-8"> tag in your header?

Lambda/Sierra15:07:55

@bhauman: No. Also not my HTML. simple_smile

bhauman15:07:27

maybe try placing it in the head of your html. and see if that helps.

bhauman15:07:46

not sure it will help

Lambda/Sierra15:07:50

@bhauman: Looks like that might have fixed it. Thanks!

bhauman15:07:05

At this point I think that should be on every default template. Adding it to the figwheel template now.

meow15:07:13

My standard index.html file, fwiw:

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
    </head>
    <body>
        <div id="app"></div>
        <script src="app.js"></script>
    </body>
</html>

Lambda/Sierra15:07:59

Is <meta charset="utf-8"> a real thing? I thought it was <meta http-equiv="Content-type" content="text/html; charset=UTF-8">

meow15:07:28

html standards have gone through a lot of changes

Lambda/Sierra15:07:50

I guess I do old-fashioned HTML.

bhauman15:07:01

At the rate its moving I think we all do old fashioned html

meow15:07:17

the html I posted is the minimal amount to be compliant with good "responsive html" practices

bhauman15:07:41

pkobrien: thanks I'll take it

meow15:07:50

html5, language set so translations work, charset, viewport for mobile devices, etc.

meow15:07:31

except the body elements are for reactive apps

bhauman15:07:11

I still don't use any of the new html5 "semantic" tags, it just never occurs to me to use them.

meow15:07:50

header, footer, main, aside, etc

meow15:07:49

(html
   [:body
    [:header {:role "banner"}
     [:nav {:role "navigation"}]
     ]
    [:aside {:role "complementary"}
     ]
    [:main
     ]
    [:footer {:role "contentinfo"}
     ]
    ]))

cfleming16:07:11

@meow: How do you paste code like that in Slack?

Petrus Theron16:07:45

my advanced compilation ClojureScript app.js file is quite large. How can I reduce the size? Is it core.async that's eating that much space?

cfleming16:07:50

(defn test [a b c])

meow16:07:46

@cfleming: you got it 😉

cfleming17:07:34

@dnolen: 0.1.56 just landed with a bunch of CLJC fixes. Still more to do but is hopefully more usable now. If you’re still having problems I’d like to know about them.

dnolen17:07:46

@petrus only the gzipped size matters

dnolen17:07:14

Size of uncompressed source - irrelevant

dnolen18:07:26

@cfleming: will give it a shot soon!

shriphani18:07:32

Hi. Is lein new mies still the recommended template? I saw no mention of it in the quickstart.

dnolen18:07:12

@shriphani: I’m actually thinking about deprecating them, don’t have any time to maintain them anymore

dnolen18:07:19

and Quick Start is a better starting point

arohner19:07:28

if I stick a transit-encoded map in a goog.net.XhrIo, it appears the xhr escapes my transit string again. Is there a way to avoid that?

dnolen20:07:35

@arohner: really? cljs-ajax and cljs-http must have sorted that out, I would look there.

arohner20:07:52

yeah, I’m not seeing anything special yet. It seems like they just do the expected (t/write (t/writer :json) x)

arohner20:07:19

amazingly, the double escape thing only happens on some websites and not others

roberto20:07:26

is there a way to make an xhr call block? I’m getting an error when I :refer <!!

arohner20:07:54

@roberto: no. JS is single threaded, so you can’t block

roberto20:07:45

okay, a better question: has anyone used clj-http with re-frame?

roberto20:07:38

err, cljs-http

arohner20:07:21

@roberto: I’m sure plenty of people have. You probably want (go (<! chan))

arohner20:07:54

in cljs-http callbacks, put results on channels. Elsewhere, take data from channels, and update UI

roberto20:07:59

yeah, that is what I’m using

roberto20:07:33

but not sure why updating the state isn’t triggering the subscriptions

arohner21:07:18

@dnolen: my double escape thing, which I know sounds super weird and sketchy 1) happens on some websites and not others 2) doesn’t appear to happen when using (t/writer :json-verbose)

arohner21:07:34

I suspect the site is monkeypatching js/String or something

dnolen21:07:57

@arohner: this not something we’re going to address at all

dnolen21:07:26

@arohner: you’re the first person to report this issue so I don’t think it’s an actual problem

arohner21:07:31

not expecting you to. It’s just weird and I’m trying to understand it

arohner21:07:36

`cognitect.transit.write(cognitect.transit.writer("json"), 3) ""[\"~#'\", 3]”"`

arohner21:07:29

different site:

arohner21:07:29

cognitect.transit.write(cognitect.transit.writer("json"), 3) "["~#'",3]"

samueldev21:07:31

anyone able to point me in the right direction

samueldev21:07:41

if I am trying to convert an array of JS maps

samueldev21:07:52

to a clojure coll of maps

johnmendonca21:07:16

@samueldev: I think js->clj may work for you

samueldev22:07:18

so when it comes to working with Om

samueldev22:07:21

as a means to learn clojurescript

samueldev22:07:39

should I ask what essentially amount to "beginner Om/CLJS questions" here, or in #C03S1L9DN, or in #C053AK3F9

samueldev22:07:04

or in #C06DT2YSY*

meow22:07:33

@samueldev: whatever gets the job done 😉

akiva22:07:50

I’d say actually #C03S1L9DN and #C06DT2YSY.

samueldev22:07:19

currently im using cljs-ajax

samueldev22:07:25

for my ajax requests

samueldev22:07:34

and its response objects are huge and seem to have the data nested inside somewhere

samueldev22:07:38

trying to figure out how to access those 😞

akiva22:07:05

I use that as well but I get a map back.

akiva22:07:14

And they are bloody huge.

samueldev22:07:50

(def app-state
  (GET ""
    {:handler (fn [response] (.log js.console response))
     :response-format :json
     :keywords? true}))

samueldev22:07:12

response logs out to this object: http://puu.sh/iLbcC/15819d9c9c.png

akiva22:07:48

Are you trying to use JavaScript to process it?

samueldev22:07:48

and i need to access (in JS syntax cuz im a noob) response.tail.arr[0]

dnolen22:07:07

@samueldev: you don’t want to debug that, you should print it to a ClojureScript thing

samueldev22:07:14

im trying to get the contents of response.tail.arr[0] in the form of a collection of clojure maps

samueldev22:07:30

this is my biggest issue right now i think, figuring out the "clojurescript" way to debug this stuff

dnolen22:07:48

from the JavaScript Console cljs.core.pr_str(foo)

dnolen22:07:57

whatever local you are trying to print

samueldev22:07:36

I don't think I have access to it like that

samueldev22:07:54

or rather I do, because its in my browser, but I don't know where

dnolen22:07:38

just type that in the JavaScript Console

samueldev22:07:57

I understand that haha

samueldev22:07:01

I mean foo in your case

samueldev22:07:16

how do I assign a local to the window so I can know what to log out?

dnolen22:07:30

you need to set a break point in your ClojureScript source

akiva22:07:49

Hah, I keep typing and then I see @dnolen typing and I’m all, ‘I defer.'

samueldev22:07:06

😛 every piece of your advice leads me to more questions... gonna use my googlefu before asking lol

akiva22:07:22

@samueldev: Are you using Figwheel yet?

samueldev22:07:37

lein new figwheel project -- --om

akiva22:07:40

Okay, good, good. The latest Figwheel allows you to set breakpoints as @dnolen just described. At the same time, you should through the Figwheel REPL be able to query defs and so forth.

samueldev22:07:21

Uncaught SyntaxError: Unexpected token debugger

samueldev22:07:39

(def app-state
  (GET ""
    {:handler (fn [response]
                (.log js/console (type response))
                (js* "debugger;"))
     :response-format :json
     :keywords? true}))

samueldev22:07:01

nvm I wasn't thinking about how this would translate to javascript

samueldev22:07:17

first thing after params in a cljs fn is a return, so that debugger would never get hit

samueldev22:07:34

sweet! progress

samueldev22:07:51

so I get this when I run cljs.core.pr_str(response) after my breakpoint

samueldev22:07:42

which appears to be a valid vector?

samueldev22:07:45

or am I crazy

samueldev22:07:23

given that that's the case, should I not be able to iterate over it and build some om components with om/build-all? all of my questions derive from the first issue I ran into:

dnolen22:07:26

just used eval'ed some bootstrapped ClojureScript from a browser REPL simple_smile

samueldev22:07:33

getting the following when I run om/build-all...: Uncaught Error: [object Object] is not ISeqable

samueldev22:07:18

complete context:

samueldev22:07:27

(defonce app-state
  (GET ""
    {:handler (fn [response]
                (js* "debugger;")
                response)
     :response-format :json
     :keywords? true}))

(defn project-view [project owner]
  (reify
    om/IRender
    (render [this]
      (dom/li nil (str (:name project) ", ")
        (dom/a #js {:href (:github-url project)} (:github-url project))))))

(defn projects-view [data owner]
  (reify
    om/IRender
    (render [this]
      (dom/div nil
        (dom/h2 nil "Project list")
        (apply dom/ul nil
          (om/build-all project-view (seq data)))))))

(om/root projects-view app-state {:target (. js/document (getElementById "app"))})

samueldev22:07:06

in other words om/build-all can't iterate over the PersistentVector? is my understanding?

dnolen23:07:05

samueldev: your app-state is borked. GET is async it’s not going to return anything meaningful right away.

samueldev23:07:30

do I need async channels to hold offon app initialization of the component then

dnolen23:07:39

you need something

samueldev23:07:49

figured as much

samueldev23:07:11

if I throw my entire om component definition and rendering code into the callback of the cljs-ajax call

samueldev23:07:13

it works fine

samueldev23:07:22

so you were right and I was just making assumptions about my error

samueldev23:07:57

(the assumption being that "oh, object object isnt iseqable? that must mean that the http call IS finished, and its the response format thats the issue")

samueldev23:07:24

oh hey you wrote the damn thing @dnolen

samueldev23:07:35

thanks for helping a noob out simple_smile

dnolen23:07:39

no problem