Fork me on GitHub
#clojurescript
<
2017-09-21
>
thheller07:09:43

@conaw are you running in node.js? then require is fine, fs.readFileSync also works

conaw07:09:52

I ended up just storing it in firebase, but the question was as to whether I could just deploy a JSON file alongside by html and css (this is for a prototype app) and require it just using cljs (rather than having to fetch the data)

conaw07:09:02

I’m not using nodejs or any server

conaw07:09:46

@madstap sounds interesting, not sure what you mean though

miikka07:09:25

@conaw, you would create a macro that's basically (defmacro include-file [path] (slurp path)) and when you call it from ClojureScript, it expands to a string that contains the contents of the file at the compile time.

thheller07:09:34

@conaw then ajax is the way to go, please don’t do the macro. its a terrible idea

miikka07:09:47

@thheller, what, it's a great idea

thheller07:09:58

no its is absolutely terrible

miikka07:09:17

It's simple and it works, I've used it many times

thheller07:09:24

it turns your data into compiled javascript code

thheller07:09:35

which means it gets optimized by closure

thheller07:09:05

which may destroy your data but definitely will make everything slower depending on the amount of data you are working with

miikka07:09:17

it will optimise my string?

miikka07:09:37

i mean, i guess it will throw it away if i don't use it, but other than that

thheller07:09:49

ah sorry, optimized only applies if you parse the JSON server side

miikka07:09:59

right, okay, that's ripe with problems

thheller07:09:01

but still having a gigantic string in your code is a bad idea

vinai07:09:58

In a clj/cljs app I'm building I'd like to split some parts into separate pages instead of bundling all of the client side code into one single page app. For example the registration, it doesn't make a lot of sense to have that code bloating the main app. Is there a way to tell the compiler to build parts of the app as separate cljs "sub-apps"?

miikka07:09:46

@thheller, what problems would the gigantic string cause?

thheller07:09:11

doesn’t matter much if you work with 1kb .json files

thheller07:09:16

just use XHR to load the file on load. the initial .js load will be faster, the .json is loaded async and is cacheable

thheller07:09:22

filesize is the problem. as it will become size of .js + size of .json. so if you have a 2mb .json file the browser will do a blocking load that takes forever if inlined into your .js

thheller07:09:35

@vinai :modules is what you are looking for, it splits the code based on the namespaces you provide

vinai07:09:57

Ah, thanks, that gives me something to google for!

miikka07:09:28

Okay, megabytes of JSON is bad, yeah

tatut10:09:43

any idea why cljsbuild fails with NPE

tatut10:09:47

java.lang.NullPointerException
	at java.util.regex.Matcher.getTextLength(Matcher.java:1283)
	at java.util.regex.Matcher.reset(Matcher.java:309)
	at java.util.regex.Matcher.<init>(Matcher.java:229)
	at java.util.regex.Pattern.matcher(Pattern.java:1093)
	at clojure.core$re_matcher.invokeStatic(core.clj:4801)
	at clojure.core$re_matches.invokeStatic(core.clj:4831)
	at clojure.core$re_matches.invoke(core.clj:4831)
	at cljs.util$compiled_by_version.invokeStatic(util.cljc:42)
	at cljs.util$compiled_by_version.invoke(util.cljc:39)
	at cljs.closure$compile_from_jar.invokeStatic(closure.clj:578)
	at cljs.closure$compile_from_jar.invoke(closure.clj:571) 

tatut10:09:26

and how to debug it, I tried adding the :verbose compiler option but it doesn’t output anything more

tatut10:09:30

oh, it looks like it’s trying to determine if a compiled js file has the same version as the current version…. removing all generated js files fixed the issue

hlolli12:09:45

is this expected?

ui.core> (first (:responses @app-state))
#object[XMLHttpRequest [object XMLHttpRequest]]
ui.core> (object? (first (:responses @app-state)))
false

hlolli12:09:04

this seems better alternative

ui.core> (instance? js/Object. (first (:responses @app-state)))
true

noisesmith12:09:12

what is that . doing there?

noisesmith12:09:01

it looks like object? is really checking for what on the jvm we'd call a PoJo

cljs.user=> object?
#object[Function "function (a){return null!=a?a.constructor===Object:!1}"]

noisesmith12:09:11

if the constructor wasn't Object, it will return false

hlolli12:09:14

yes the dot was not needed. PoJo, that's new to me.

noisesmith12:09:46

"plain old java object"

noisesmith12:09:02

in other words, it's got nothing special, in clojure we'd just use a hash-map

noisesmith12:09:36

if Object was the constructor, it's not an instance of anything interesting (though of course being js it could still be or do anything at all)

hlolli12:09:41

what seperates one json object from another in javascript, is it the metadata?

noisesmith12:09:01

json is a string format - but when you consume it you get Object instances

honzabrecka12:09:08

Have anyone encountered the following error when compiling in advanced mode (clojure 1.9.0-beta1, cljs 1.9.908)?

.../cljs/core.js:3579: ERROR - Parse error. primary expression expected
case ##Inf:

darwin12:09:37

@honzabrecka look into #cljs-dev, it was discussed there

darwin12:09:13

tools.reader related

hlolli12:09:15

I guess I need to look at objects differently, thought they all were keys connected to values or functions and hence, all the same.

hlolli12:09:50

function can be a cunstructor, I can't see why I'd like to see that truth as object

noisesmith12:09:48

If the constructor was Object, you know it's not "special" and I assume there are cases where that matters. For example, if the constructor was Object, you could use goog.object to list and iterate keys etc. and not run into the gotchas that you would with weirdly behaved things like the DOM that are almost well behaved but... not.

noisesmith12:09:29

normal js libs use Object like we do hash-maps

hlolli12:09:03

ok, can this be seen in cljs when the return value is #js {:key "val"} as opposed to #object[] ?

noisesmith12:09:55

I hope someone else can give you an answer for that, but - sounds plausible to me

hlolli12:09:38

ok but I think I get your point, thanks for clarifying!

zentrope18:09:50

Is there a known issue using clj 1.9-beta1 with CLJS and cljsbuild?

zentrope18:09:38

ERROR: JSC_PARSE_ERROR. Parse error. primary expression expected at /Users/.../target/cljsbuild-compiler-1/cljs/core.js line 3579 : 6

bronsa18:09:38

yes, read above -- this is caused by a change in how 1.9-beta1 prints infinity/nan, i believe there's already a fix in CLJS's jira

zentrope18:09:14

Ah, I'm here via IRC, so can't read above. I'll dig out the behemoth. ;)

Garrett Hopper21:09:50

Is there an alternative version of hash that is consistent between clojurescript and clojure?

arkh21:09:18

@ghopper do you mean a consistent ordering of keys or consistent in another way?

Garrett Hopper21:09:43

Consistent as far as (hash 1) in clj being equal to (hash 1) in cljs. I'm using the hash to generate a css class name, but I didn't realize integers weren't hashed in the same way.

dpsutton21:09:17

You run into different size of integer space perhaps?