Fork me on GitHub
#clojurescript
<
2017-07-24
>
ilevd04:07:00

There is require('store') in the example usage https://github.com/marcuswestin/store.js, how can I do it in ClojureScript? Should I use some lib for requiring?

srinidagda06:07:44

Hi, I am curious about clojurescript. Can you we develop Mobile apps through clojure script? What should I learn to that?

vetalik06:07:27

Hello! There is possibility to develop React-Native apps using ClojureScript with https://github.com/drapanjanas/re-natal It is quite easy to setup, and you can select from several React Wrappers

borkdude09:07:40

I’m a bit surprised I’m getting a Closure optimization error on this in production:

(def in-iframe? (not= (oget js/window "self") (oget js/window "top")))
where oget is from cljs-oops (https://github.com/binaryage/cljs-oops)

thheller09:07:16

@borkdude and without oget? just js/window.top and js/window.self?

borkdude09:07:29

It seems with

:pseudo-names true
I don’t get the extern error, while I’m using this to find the error 😛

magra10:07:13

I put german postal codes and locations in a map. The postal codes are strings, like "01067". I use (get post-code-map post-code-lookupstring). This works 99% of the time but on one entry, that looks exactly like all the others and is the first in the literal where the map gets defined, it returns nil. When I debug print the lookupstring lookes like the others. type returns function String () { [native code] } like the others. What am I not aware of regarding js or cljs strings or maps?

featalion10:07:18

@magra are you sure, that the key exists when get returns nil? it seems like the key mismatch in some way, for example it can contain O (big o) character instead of 0 (zero), or spaces, or invisible / control characters

magra10:07:54

When the get returns nil, I debug print the lookupstring to the console. When I copy that to the repl the get works. So I will look at the invisible characters.

magra10:07:57

@featalion You are right: I debug-printed characters befor and after the string so I would see spaces. But the thing has a count of 6! Thanx!!

borkdude10:07:41

What’s the correct way to require cljs.spec.alpha, I suppose you need to refer-macro def?

dnolen10:07:41

@borkdude just require it

dnolen10:07:21

macro inference is a thing now and cljs.spec.alpha is setup correctly for it

octahedrion11:07:15

I'm requiring clojure.spec.alpha in a cljs and it works - why?

dnolen11:07:38

@octo221 we autoalias namespaces clojure.* -> cljs.*

dnolen11:07:52

removes pointlessly trivial reader conditionals

borkdude11:07:32

I get an error on this:

(s/def :foo/bar ...)
, Uncaught TypeError: M is not a function

borkdude11:07:44

when doing advanced compilation

magra11:07:19

@featalion it was a 65279 zero-width no-break space. I should have sanitized the data I grabbed from the internet. Thanx again!

featalion11:07:27

@magra glad to know that helps (-:

shakdwipeea12:07:09

Hi everyone, I had a reagent based app and I wanted to integrate a WYSIWYG editor ... Are there any good cljs libraries for this.. or use js libraries like quill? I plan to have good table support which is not very solid in quill..so something like slate maybe..

shakdwipeea12:07:40

I am really confused at this point..with so many js options..

dnolen12:07:14

@borkdude that’s really not enough information, make something minimal

dnolen12:07:37

that should work, if it doesn’t open a JIRA issue

lwhorton12:07:21

Does anyone know of an existing b-tree / rbtree / 234tree, etc. library? I could eventually write some trees myself, but it seems like this is a solved problem. I have considered loom, and i guess technically a directed acyclical graph is a tree... but its not exactly what im looking for.

hmaurer12:07:21

A directed acyclic graph is not a tree

borkdude12:07:54

Can’t reproduce it with a small project

dnolen12:07:33

@borkdude are you embedding your defs in some other macro?

borkdude12:07:49

no, top level

borkdude12:07:59

it’s in a .cljc file though

borkdude12:07:12

but even that doesn’t cause an issue in a small project

urbank12:07:59

@lwhorton I believe @tonsky implemented a persistent B-tree for #datascript

dnolen12:07:22

@borkdude that sounds quite strange

joshkh14:07:02

how do you guys and gals go about compiling the third-party less/sass in your cljs projects when they're from, say, npm or bower? i don't want to expose the entire node_modules dir in my public resources folder, and yet (obviously) an @import in the compiled css can't reach outside the public folder down to the node_modules dir.

ajpierce15:07:42

After reading https://clojurescript.org/news/2017-07-12-clojurescript-is-not-an-island-integrating-node-modules, I was wondering: Do we still need to define externs for all the npm libraries we would include in a project?

spinningtopsofdoom15:07:29

If the library dynamically generates public names Google Closure will need externs IIRC.

spinningtopsofdoom15:07:41

like

var foo = {};
bar = "hello"
foo[bar] = 1

export foo;

borkdude15:07:14

It turned out this was the error:

(def ^:export in-iframe?
  (not (identical?
     js/window.self
     js/window.top)))
vs.
(def ^:export in-iframe?
  (not=
   js/window.self
   js/window.top))
The latter one creates unexpected bugs that are hard to trace back to the origin

dnolen15:07:52

at first glance, not clear to me why that would be problematic

borkdude15:07:38

The weird thing is that this code loads fine in the top frame, but not in a child iframe… or at least, this is where the errors come frome

borkdude15:07:20

Well, the expression yields true, but after it we get all kinds of errors like M is not a function in the iframe. Very weird.

darwin15:07:24

@borkdude one has to be pretty careful about boundaries of different builds from multiple js contexts, once I ran into very strange issues by calling cljs functions in “foreign” js context because they were compiled as a different cljs build and in advanced mode mangling was slightly shifted

darwin15:07:30

e.g. passing a persistent data structure created by :advanced mode build A into some function which was compiled in :advanced build B will most likely break if the code differs

borkdude15:07:33

We use the same advanced build in both frames

borkdude15:07:52

and we only communicate by sending json back and forth

darwin15:07:18

ok, then this should not be the issue

borkdude15:07:53

I also don’t see what this has to do with advanced builds… but in none we get no error.

darwin15:07:17

not= is using protocols, and protocol method check is mangled

darwin15:07:40

so it by “coincidence” could hit some other mangled name

darwin15:07:58

and decide to call procotol method which is most likely something completely unrelated

borkdude15:07:17

could be, it sounds like identical? is the better choice here

darwin15:07:38

you just worked around the issue, but didn’t fix the root cause, I would say

borkdude15:07:29

True, I don’t understand the root cause, which drives me crazy 😉

darwin15:07:27

I would recommend compiling it in :advanced without pseudo-names but with source maps, then try to investigate exact cause

borkdude15:07:24

@darwin That’s exactly what I’ve been doing. With pseudo-names we don’t get the error.

darwin15:07:26

in your iframe x y are not identical, so it takes that protocol code path, which is somehow problematic in your case

borkdude15:07:47

That’s very likely!

darwin15:07:00

it could be that there is something with short names like “a” or “M” registered as properties on the window object x and those short names by coincidence match mangling of protocol methods from closure compiler

darwin15:07:00

look at the generated code and maybe inspect what exactly those props are and where they came from

thheller15:07:43

js/window in general is a dangerous object to use, did you check if window.top and window.self get mangled? maybe there are no default externs for it

thheller16:07:18

also in case of frames they may be instances of two different VMs

borkdude16:07:21

I had (oget js/window "top") before, same error

thheller16:07:23

they will never be identical

borkdude16:07:43

(oget is from cljs.oops)

thheller16:07:04

AFAIK that emits window["top"] which may not be equal to window.top in case of native objects

thheller16:07:48

which error exactly do you get anyways?

borkdude16:07:00

@thheller do you have a better way of checking if code runs inside an iframe?

darwin16:07:14

cljs.oops emits window["top"] but that will get rewritten into window.top by closure compiler (to save 3 characters) 🙂

borkdude16:07:32

so writing window.top has the same effect?

thheller16:07:11

do you just want to prevent embedding in iframes?

borkdude16:07:36

no, I have some code that should be ran inside an iframe, but not outside of it. we use the same source for both frames

borkdude16:07:09

so we should be able to say: (if in-frame? … …)

darwin16:07:35

@borkdude in case of js/window.top yes, because window.top has default extern, and “top” does not contain any characters which would prevent dot-notation

darwin16:07:09

closure compiler will rewrite string-name property access to dot notation if possible

thheller16:07:26

I’d probably write 2 different start functions that set code up properly

thheller16:07:31

so it never needs to be detected?

borkdude16:07:04

It might have something to do with -equiv like @darwin suggested

thheller16:07:41

protocol dispatch in window is problematic and should be avoided

thheller16:07:23

its better since https://dev.clojure.org/jira/browse/CLJS-1658 but fast path protocols don’t use the sentinel

thheller16:07:59

I assume you control the HTML that gets generated for both the normal and iframe versions? can’t you just set a variable in the iframe version and test that instead?

borkdude16:07:09

It doesn’t work like that in our case (yet), but it might be a good idea to go that way.

borkdude16:07:38

The problem is that we load this HTML both in an iframe but also outside (when creating a PDF), so it’s not that simple

rnagpal17:07:03

What is the evaluation order of clojurescript.

rnagpal17:07:10

If I have 9-10 files

rnagpal17:07:16

and they call functions in them

rnagpal17:07:30

which one of the function calls gets executed first

noisesmith17:07:58

generally you want to avoid even having to ask the question by never having top level side effects in the files

noisesmith17:07:34

but the require blocks are loaded before the rest of the file, recursively, so the first full file to be loaded is the one at the very bottom of the recursive first requires

noisesmith17:07:48

ie. the first require of the first require of the first require etc.

rnagpal17:07:34

Thanks @noisesmith for the reply, I agree this should be avoided and can be by encapsulating in functions and calling them a a right sequence, which is done by the main file Where can I read more about the evaluation order

noisesmith17:07:48

it’s simple depth first

noisesmith17:07:59

all requires of the first require are loaded before the second require is run

noisesmith17:07:16

it’s somewhere in the core clojure docs I assume but it’s not a complicated algo

ag18:07:18

can anyone suggest a name for cljs fn that:

Returns false:
   - for string if it's blank,
   - for number - if it's zero, `NaN` or `Infinity`
   - for collection - if it has no elements or has only nils 
   - for everything else - if it is nil
these don't feel quite right: totally-empty? empty-yo? way-empty? kinda-empty? emptyish?

bostonaholic18:07:34

pun(ish) intended

bostonaholic18:07:29

with the understanding that zero and Infinity are “values”

bostonaholic18:07:22

to me, you’re code is asking “is this thing valuable?”

samcf18:07:24

valid-foo?

jjfine18:07:20

i'm a bit confused...all the names you suggest are maybe opposite of what the spec implies: (totally-empty? nil) => false and (totally-empty? "abc") => true seems strange

ag18:07:24

oh, right... I totally have it backwards

noisesmith18:07:11

I’ve used absent? for a similar predicate

noisesmith18:07:36

but returning true for 0 / nil / () etc.

noisesmith18:07:52

or if you want false for those, I would call it present?

mfikes18:07:29

@rnagpal With 1.9.456 a change was made to ensure that namespaces are loaded in the order specified in the ns form.

noisesmith18:07:57

@mfikes wow super surprising that this was ever false - was this a cljs bug?

noisesmith18:07:53

OK “Defect” means yes then 😄

noisesmith18:07:08

thanks for the info

dpsutton19:07:18

haha there was a classic argument that alex miller had with someone about why empty? didn't obey these semantics with empty string, numbers, etc

dpsutton19:07:46

like several hours, people chiming in with set theory, the works

noisesmith19:07:34

haha, one of those “depends on what your definition of is is” arguments

martinklepsch20:07:49

what’s a good cljc way to combine two strings into one hashed value so that it returns the same hash for the same two input strings?

martinklepsch20:07:24

I could just use (str a b) but I feel like that might be pretty inefficient when done for large amounts of pairs?

ag20:07:07

I guess I have to get down to the lower level of abstraction first and write a) fn that checks if number is finite and non NaN b) if string is indeed has type String and then run clojure.string/blank? on it. But I still would struggle to name these fns

ag20:07:41

true-number? non-blank? or truly-blank?

ag20:07:24

as it turned out, you don't have to check if it's string to use clojure.string/blank? on it

noisesmith20:07:21

@martinklepsch wouldn’t (hash [str1 str2]) work?

martinklepsch20:07:24

I could just use (str a b) but I feel like that might be pretty inefficient when done for large amounts of pairs?

noisesmith20:07:21

@martinklepsch but that would have collisions for “hel” “lo” and “h” “ello”

noisesmith20:07:17

the hash of [a b] is the same between clj / cljs

noisesmith20:07:34

and is much harder to make collide

martinklepsch20:07:00

@noisesmith yeah, your suggestion is best I presume, didn’t think of it haha

tiagoantao23:07:33

Hi. Anyone here using :npm-deps with leiningen and figwheel? I am having a couple of problems. First it seems that figwheel uses Clojure 1.8 (the sidecar POM has that dependency and indeed the compiler refuses the npm-deps option, even if I specify 1.9.671 on project.clj). Second the google closure compiler does not like some modules and throws out some errors, some of these errors could be solved by parametrizing google closure, but I have found no way to do that from the project.clj file

anmonteiro23:07:32

@tiagoantao I don’t understand what you mean by Clojure 1.8 or something. You just need to specify your version of ClojureScript in the dependencies

anmonteiro23:07:46

the ClojureScript compiler should work with Clojure 1.8

anmonteiro23:07:57

wrt. the errors, see :closure-warnings

tiagoantao23:07:52

@anmonteiro When I do lein cljsbuild once everything seems to work fine. But if I do lein figwheel I get an error where the :npm-deps is not an acceptable compiler option (which you would expect pre-1.9.518), when I looked at the maven POM for figwheel-sidecar it has a dependency for 1.8 and I strongly suspect that it uses 1.8 for compiling code even if you specify 1.9. With regards to :clojure-warnings: going to test it right now, thanks!

dnolen23:07:41

@anmonteiro Figwheel doesn’t accept options it doesn’t know about - you need to configure it

anmonteiro23:07:44

I suspect that’s a Figwheel problem checking the ClojureScript options

anmonteiro23:07:01

^ what David said

tiagoantao23:07:20

@anmonteiro So I solved the second problem with :language-in :es5

tiagoantao23:07:53

@anmonteiro @dnolen With regards to figwheel, two notes: the documentation states that :compiler options are passed to to cljsbuild and, if you search figwheel code (I might have not searched sidecar) there are no explicit :compiler options there - I suspect that they are passed verbatim. Also the smoking gun of the 1.8 dependency on the figwheel-sidecar POM makes me suspect that it is using 1.8 for compilation. I emptied the maven repo and cljs 1.8 is indeed downloaded. This is just speculation, of course

dnolen23:07:22

@tiagoantao this doesn’t have anything to do with 1.8

anmonteiro23:07:22

it’s not about the version of ClojureScript being used

dnolen23:07:30

I would stop thinking about that

anmonteiro23:07:30

if you have one in your dependencies, it’ll use that one

anmonteiro23:07:44

I’m trying to find the option you need for Figwheel

anmonteiro23:07:57

something about schema checks

anmonteiro23:07:43

@tiagoantao ^ add :validate-config :warn-unknown-keys to your figwheel options

anmonteiro23:07:53

the problem should go away

anmonteiro23:07:12

or use Figwheel 0.5.11 which has :npm-deps in the option schema

tiagoantao23:07:29

@dnolen @anmonteiro This newbie profoundly thanks both of you for your wizard help. Your magic worked!