Fork me on GitHub
#clojurescript
<
2017-05-10
>
Geoffrey Gaillard00:05:49

It did the trick ! I also used :print-input-delimiter true and used this perl script to split the output file on the // Input delimiter. Then sorted the files by descending size.

#!/usr/bin/perl

undef $/;
$_ = <>;
$n = 0;

for $match (split(/(?=\/\/\sInput)/)) {
      open(O, '>temp' . ++$n);
      print O $match;
      close(O);
}

john03:05:22

Anyone seen a situation where a map is in atom a and (swap! a assoc-in [:L1 :L2] val) fails silently if :L2 already exists. But succeeds if :L2 does not exist in the map?

john03:05:13

nevermind. I was doing another assoc-in elsewhere, after the fact, clobbering this particular swap!.

iku00088805:05:46

Has anyone tried using goog.net.Jsonp recently? I can require/import XhrIo but no luck with the Jsonp

thheller07:05:10

@iku000888 what is Jsonb? I only know of JsonP?

mike_ananev08:05:28

Hi! I'm trying to use Pedestal ( clj + cljs SPA). All browser show me a message that thet can't load my SPA: Refused to load the script 'http://localhost:8080/js/compiled/app.js' because it violates the following Content Security Policy directive: "script-src 'unsafe-inline' 'unsafe-eval' 'strict-dynamic' https: http:". 'strict-dynamic' is present, so host-based whitelisting is disabled.

jimmy08:05:48

@mike1452 post your answer on #pedestal

iku00088808:05:51

@thheller sorry, it is jsonp. I can't stop making that typo for some weird reason. 😞

iku00088808:05:54

(and I did not make that typo in my test code :))

iku00088808:05:24

and for my specific problem cljs-ajax did the job at the end of the day, so everything is good except it was a weird experience.

thheller08:05:26

@iku000888 goog.net.Jsonp is a class so use it via (:import [ Jsonp]) and then just Jsonp. a blank goog.net.Jsonp is not correct

iku00088808:05:19

@thheller thx. Will try that...

thheller08:05:01

(js/goog.net.Jsonp. ...) also works but :import is better. ensures that you don't forget the require/import

akiel09:05:31

Hi. Does someone know why cljc namespaces are analysed every time a namespace is compiled which depends on the cljc namespace? This results in multiple analyses of the same cljc namespaces during one compilation. I have verbose compiler output on and see many “Reading analysis cache for” messages.

pesterhazy09:05:36

@thheller a blog post or piece of documentation explaining requires/imports in cljs, especially wrt GCL, would be great

martinklepsch10:05:21

pesterhazy: I’ve been thinking about writing that post. Can you scan your code for some places where you found it non-trivial to nail down the syntax?

martinklepsch10:05:06

Things I can think of : - Constructors - regular functions - constants - things like goog.Timer where the namespace has functions but also is a constructor What else?

pesterhazy10:05:22

that's a pretty good list

pesterhazy11:05:25

goog.async.Delay is also a candidate

pesterhazy11:05:25

- how do you call things? (goog.async.nextTick) works, as does (goog.async/nextTick) and (without adv comp) (js/goog.async.nextTick)

pesterhazy11:05:49

- goog.object as special case?

pesterhazy11:05:32

- constants defined from outside

pesterhazy11:05:46

(in project.clj or whereever)

pesterhazy11:05:21

closure-defines

martinklepsch11:05:32

goog.async.Delay is just a constructor no?

martinklepsch11:05:57

goog.object - what’s special about it?

martinklepsch11:05:17

constants defined from outside - referring to closure-defines here or something else?

pesterhazy11:05:24

clojure-defines, yes

pesterhazy11:05:49

goog.object is loaded by default, for one thing (so you can in principle skip requiring it)

pesterhazy11:05:04

correct about Delay

martinklepsch11:05:05

Will try to put something together tomorrow

anmonteiro15:05:28

@martinklepsch the goog.string.format also deserves to be included IMO

martinklepsch16:05:38

@U0CK4CKAP it’s special because it’s a namespace with a single function?

martinklepsch16:05:55

is the function goog.string.format/format or goog.string/format?

anmonteiro16:05:02

@martinklepsch yeah, it’s a quirk that a lot of people fall into:

(require '[goog.string :as string]
         '[goog.string.format])

(string/format ....)

martinklepsch16:05:15

Ah interesting. Did not know that one. thanks

martinklepsch16:05:06

I’ll ping you some time tomorrow with a draft, maybe you can just briefly check if there are no obvious mistakes

martinklepsch16:05:36

@U0CK4CKAP do you know why it is done that way? DCE I presume?

anmonteiro16:05:30

sounds good 👍 I don’t know why it’s done that way, I simply accepted it as a quirk of GCL without thinking

pesterhazy09:05:09

I'm usually using trial and error, but it would be great to have a few paragraphs by someone who speaks from (more) authority

qqq10:05:31

in cljs, how do I convert a char (which is represented as a string) to itsw unicode value ?

iku00088810:05:33

String.prototype.charCodeAt() ?

iku00088810:05:47

Just a quick google search though 🙂

thheller10:05:57

@pesterhazy :import classes and :require namespaces is about it.

qqq10:05:00

here's what's throwing me off; cljs chars are js strings of length 1 right ?

qqq10:05:24

so I have some weird code where (.charCodeAt (str some-char-object) 0) works but (.charCodeAt some-char-object 0) fails

thheller10:05:20

@qqq what type is some-char-object?

qqq10:05:35

as determiend by (type some-char-object) ?

qqq10:05:59

function String() { [native code] }

qqq10:05:45

I found my problem

qqq10:05:01

these 'chars' are read in from a fule, most of them are of the format "\u####"

qqq10:05:11

but there are a few 'null's passed in a s well

qqq10:05:15

which are definitely HNOT chars / strings

qqq10:05:30

basically, 1% of the data is evil and I did not reailze it

qqq10:05:01

out of 531 entries; 7 are NOT chars; the rest are chars; that threw me off

miikka10:05:31

Should ... work as an identifier in ClojureScript? (def ... :foo) works in Clojure.

qqq10:05:37

does this come from using as-> ?

qqq11:05:59

@darwin : is ocall supposed to work on string types? i.e. (ocall s "charCodeAt" 0) when s is a string

darwin11:05:49

@qqq yes, I believe

darwin11:05:05

any problem in that? s is a String object in JS, so it has normal methods like your charCodeAt

qqq11:05:35

let me get a minimla fialing test

qqq11:05:40

(. js/console log "init: ")
  (. js/console log 
     (ocall "abc" "charCodeAt" 0))

qqq11:05:55

that code gives me: Error. Oops. Unexpected object value (string)

qqq11:05:27

Can you replicate this issue? my cljs compiler has been funky latetly

darwin11:05:51

I forgot about it, maybe we should relax it or you should do it different way just in this case

qqq11:05:02

how do I call charCodeAt ?

qqq11:05:08

I just want to fix this and moveon 🙂

darwin11:05:10

string methods have proper externs, so you can fall back to normal cljs js interop in this case it is safe

darwin11:05:20

(.charCodeAt s 0)

qqq11:05:23

(.charCodeAt "abc" 0) ?

qqq11:05:30

hmm, okay, this gave me problems in optimized build in cljs

qqq11:05:40

maybe my optimized build failure was due to something else then

darwin11:05:57

definitely something else, I would bet all string methods have proper externs

qqq11:05:00

it's 4am

qqq11:05:03

will debug this tomorrow

qqq11:05:06

thanks for help 🙂

darwin11:05:07

or you can try (.call (aget s "charCodeAt") s 0) but that is quite ugly

qqq11:05:02

same result

qqq11:05:06

bug myust be elsewhere

martinklepsch13:05:22

Wondering if anyone can comment on the idiomatic-ness / correctness of the following variants:

cljs.user=> (import '[goog Timer])
cljs.user=> (require '[goog.Timer :as timer])
cljs.user=> Timer.TICK      ;; => "tick"
cljs.user=> timer/TICK      ;; => "tick"
cljs.user=> (Timer. 1)      ;; => #object[Object [object Object]]
cljs.user=> (goog.Timer. 1) ;; => #object[Object [object Object]]

dnolen14:05:14

@akiel probably just a bug, make a minimal repro and create a ticket with that inline

akiel14:05:15

@dnolen thanks I’ll do if I find the time

aisamu14:05:26

I vote for timer/TICK, (Timer. 1) 🙃

dnolen14:05:36

@martinklepsch import is specifically for namespaces that are also constructors, I would not use require in this case

dnolen14:05:48

this only applies to Google Closure Library stuff

romain14:05:51

I have a picture or a list of pictures in a DB. I retrieve them in my server (with bytearray format). I use cljs-ajax to GET but I don't know how to handle the display

martinklepsch14:05:27

> this only applies to Google Closure Library stuff reason for that being goog being automatically defined?

romain14:05:34

I can see the object in my console #object[java.io.ByteArrayInputStream 0x51aae898 "java.io.ByteArrayInputStream@51aae898"]`

martinklepsch14:05:57

@romain I guess you’ll need to convert the ByteArrayInputStream to something that can be handled as response by your web server

romain14:05:45

How should I send the picture from the server ?

martinklepsch14:05:20

when you see something containing or similar in your JS console that usually means some object could not be coerced into a response in any better way than the string representation you’re seeing

martinklepsch14:05:13

@romain not sure how you’d send it but I guess it’s worth asking in #clojure how to send a ByteArrayInputStream as image file using ring (assuming you use ring)

romain14:05:05

Okay. I though it was more a clojurescript question

martinklepsch14:05:14

@romain try debugging your endpoint using curl, once it does what you expect you may run into clojurescript problems/questions 🙂

dnolen14:05:01

@martinklepsch the reason being who would do that except Google Closure Library

dnolen14:05:21

that’s an impossible pattern for Clojure

Pablo Fernandez14:05:42

Doen anybody know how is cljs ajax supposed to deal with binary data? It returns a value of type #object[String "function String() { [native code] }"] and I'd like to get a nodejs buffer or a byte array or something like that.

len15:05:07

When we do a release of our cljs app, built with lein cljsbuild is there a way to incorporate a build number or release number into the compiled app ?

len15:05:33

Ahh I see :closure-defines for :compiler-options should do the trick

fabrao16:05:39

Hello all, Why this

curl "https://*******.com/**********/servicedesk/odata/login?$format=JSON" --data "username=*********&password=********"
the response is ok and
(ajax/ajax-request
   {:uri "https://*******.com/**********/servicedesk/odata/login?$format=JSON"
    :method :post
    :params {:username "********"
             :password "********"}
    :format (ajax/url-request-format)
    :response-format (ajax/json-response-format {:keywords? true})
    :error-handler #(js/console.log "ERRO !!!")
    :handler #(js/console.log %)
    :headers {"Origin" ""
              "viaUI" "1"}
    })
Gives this error?
XMLHttpRequest cannot load https://*******.com/**********/servicedesk/odata/login?$format=JSON. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin '' is therefore not allowed access.

verma16:05:10

@fabrao you most likely need to check your CORS configuration on the host you’re trying to call.

fabrao16:05:08

verma, I can´t verify the server, but why in curl it works?

verma16:05:20

curl is different from browser since browser will have additional restrictions to call cross site resources

verma16:05:49

if you write a server side function that calls the URL, it will work and is equivalent to what curl is doing

verma16:05:57

its a browser restriction

fabrao16:05:12

so, I have to write server side function to call this ajax-request and use cljs -> server to verify?

verma16:05:48

When I cannot reach a host directly from my browser, I usually route them through my own backend, yes.

fabrao16:05:56

I tried it in electron app and this problem does not happen

verma16:05:30

yes, it won’t, these policies are actively enforced in browsers only afaik

fabrao16:05:32

oh, maybe electron is calling direct to server

fabrao16:05:59

even the app is clojurescript

verma16:05:16

well, electron may call direct, since the electron runtime is not enforcing CORS

fabrao16:05:06

now I understand the flow and restriction, many thanks for ur help Verma

verma16:05:44

no problem :thumbsup:

fabrao16:05:47

is this all for security reasons?

verma16:05:52

yes, very much so

lepistane16:05:35

do i need to do something to response i get with ajax-cljs ? i wanted to iterate through json i got ( [ {map1} {map2} ] but i get [object Object] is not ISeqable in browser what do i need to do to iterate over that list of maps?

romain16:05:27

@martinklepsch thanks for pointing me curl. I wasn't understanding why the response type was text/html and it was because of double wrapping the response lol

thheller16:05:44

@lepistane try (js->clj json-object)

romain16:05:57

Now I get the image, I need to find the proper way to display it in a html attribute

qqq17:05:39

I have a piece of code which works fine in optimizations none, but breaks under optimizations advanced. I'm 99.9% sure it has nothing to do with name mangling of js functions being called. I have a data file (531 lines) -- all lines parse + display fine in optimizations none Only some of the lines display fine under optimizations :advanced -- in particular, lines where the charAtCode is < 128. For some weird reason, for lines with unicode vhars, somethin breaks. To repeat: I have 531 lines, some of which use char < 128, some use unicode. optimizations none/advanced agree on the < 128; but diverse on unicode. I'm not even sure what to Google for. Anyone run into a similar problem before?

rauh17:05:37

@qqq have you tried advanced + pseudo names?

lepistane17:05:50

@thheller couldnt make it work this is my intention 1. have spring backend online with endpoints that i shoot at with cljs-ajax 2. use response and write on page using reagent closest i got is write response on console but even that i cant iterate through (js->clj json) didnt help

qqq17:05:43

@rauh: I should clarify. My functions return [:ok data] or [:error msg] so I'm not getting exceptions advanced/none, for char < 128, both return the same [:ok data] then, for unikcode chars, none returns [:ok data] while advanced returns [:error msg]

qqq17:05:54

and the error is due to some string/char comparison

rauh17:05:45

@qqq Some code would probably help. I have no clue what you mean with "char < 128"

qqq17:05:55

yeah, sorry about this, the code is a giant mess and I don't havea minimail failure case yet

qqq17:05:05

perhaps I should focus on creating a very small text 3example first

qqq17:05:47

in short, each of the 531 lines contains a single char; some chars have asci value < 128, other are full unicode; and the ful unicode ones behave differently under optimizations advnejd/none; but I should make a minimal failure example

qqq19:05:01

@darwin : nice; thanks, I would never found that myself

danp19:05:45

Hi all, I posted this to #clojure, then realised this may be a better forum. Hoping someone can help 🙂 I set up lein on a cloud9 container a few days ago and was trying to run lein figwheel. I've set :verbose true in the project.clj compiler details, but I'm getting nothing more verbose than Subprocess failed after Compiling resources/public/js/compiled/out/cljs/core/async.cljs. Nothing seems to be output to figwheel_server.log, so was wondering if anybody knows of anywhere else it might be logged?

qqq19:05:18

1) My cljs code requires 100kb of data to run. 2) Apparently hardcoding this data by (1) reading it in via a clj macro, parsing it, and storing it as cljs data structures is not a good idea -- as it causes the cljs compiler to run for very long time and ver long compile cycles (who'd thought!?) 3) So now, my question is: what is the best way to rxload this data at runtime?

thheller19:05:48

@qqq probably best to load it via xhr

qqq19:05:23

so it's a bad idea to encode it into a base 16 string, hard code it as a var in index.html and have cljs parse it? 🙂

qqq19:05:29

I'm only half joking.

thheller19:05:40

sounds like a terrible idea yes

qqq19:05:54

here's what I don't like about xhr

thheller19:05:59

xhr lets you take advantage of http caching and the like

qqq19:05:01

I have a buncy of global functions that depend on this 100kb of data

qqq19:05:16

if I load thsi via xhr, now, suddenly, these functions need to take an additional argument, or depend implicitly on the vaue of some atom

qqq19:05:29

this is what initially motivated me to "compile everything in as a string"

thheller19:05:13

well you'll probably have start fn, just make sure everything is setup properly before the app does anything and you should be fine

thheller19:05:48

its a good idea to never have any global state, so I usually don't mind the additional argument

qqq19:05:10

this isn't global 'state' so much as global 'constants'

qqq19:05:23

so concrete example

qqq19:05:45

if you'Re dealing with fonts / glyphs, you need to store the buonding boxes of each (font-family, unicode-id) pair

qqq19:05:57

this is static data; It changes less frequently the cljs compiler versions

qqq19:05:08

so either I hard code this data .... or I pass it around all the time

thheller19:05:40

thats probable fine in a volatile! or atom but passing it around is valid as well

qqq19:05:29

I guess the problem is,I'm not genunely asking for an opinuion: I think I've already subsconsiouly deicded I want to hard code the data, and is now just looking for a way to do so

thheller19:05:55

well ... gl then

qqq19:05:33

sorry for the confusing quesdtino; your arguments are valid; I need to figure out why I'm so attached to hard coding this data

thheller20:05:06

I understand the resistance to passing around extra arguments ... I never wanted to do that. nowadays I'm doing it everywhere and hate the places I didn't. usually I have something like context I pass around as the first argument to any function that needs any kind of state

thheller20:05:37

which is just a map containing that state .. makes things a ton easier to test

qqq20:05:43

maybe you can help me work through this:

thheller20:05:55

not expecting any global state to be set before running a function etc

qqq20:05:19

(def data [hard coded])
(def c1 (func of data))
(def c2 (func of data))
(def c3 (func of c1 c2))
where c1, c2, c3 are caches of expensitve computations

qqq20:05:37

now if I blindly added data as an arg

qqq20:05:47

access to c1, c2, c3 becomes(c1 data) , (c2 data) ... and I'm recomputing there

qqq20:05:53

this seems ugly/hairy

thheller20:05:10

just make c1,c2,c3 functions that take the context I mentioned as an arg

qqq20:05:32

suppose function 'foo' uses c1, c2, c3; I don't want c1, c2, c3 to recompute

thheller20:05:41

context contains the data but also a cache, so the fns can either look up the data from cache or calculate it and put it in the cache

qqq20:05:54

so now the context isn't pureany more

qqq20:05:00

it's stateful nd being modified ?

thheller20:05:21

never said context to be pure .. it is for state

thheller20:05:26

but pure enough

qqq20:05:33

I (incorrectly) assumed context was pure.

thheller20:05:50

context as {:data [...] :cache (volatile! {})}

qqq20:05:00

so now, in teh hard code approach, IK'm guaranteed that data, c1, c2, c3 stay the same .... but with te context approach, I lose that guarantee

thheller20:05:05

(defn c1 [ctx] ...)

thheller20:05:39

calculation is lazy so if c1 is never called nothing happens

thheller20:05:10

no idea what you are doing so that might not be a useful property

thheller20:05:36

I just code that way, it is working well for me. no idea what everybody else is doing.

qqq20:05:18

I appreciate you sharing this approach, and one day I may switch to it; but I don't think it's going to work for me right now.

thheller20:05:43

also don't overthink it

thheller20:05:48

100kb is nothing

qqq20:05:07

it's making cljs behave very weird

qqq20:05:14

err, the cljs compiler that is

thheller20:05:24

yeah you don't want to compile data. that doesn't make sense

qqq20:05:43

optimizations none compile time went from 1s to 5s, and I have to constantly clear the cache

qqq20:05:01

I suspect the problem may be I'm parsing the 100kb data into lots of tiny cljs data objects

qqq20:05:07

then the closure compiler is trying to optimize it

thheller20:05:13

yeah basically that

thheller20:05:05

xhr is my recommendation .. HTML is an option but you gain almost nothing over xhr

qqq20:05:20

does HTMl guarantee that script tags are executed in order?

thheller20:05:27

yes (unless you use the async attribute)

qqq20:05:34

if so, I can hard code my data as json in a script tag above when I load my cljs code

qqq20:05:55

alright, I think I'll go with html hard coding then