This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-07-24
Channels
- # beginners (10)
- # boot (14)
- # cider (80)
- # clara (1)
- # cljs-dev (19)
- # cljsrn (7)
- # clojure (284)
- # clojure-france (4)
- # clojure-italy (57)
- # clojure-poland (8)
- # clojure-russia (10)
- # clojure-spec (65)
- # clojure-uk (155)
- # clojurescript (156)
- # code-reviews (6)
- # copenhagen-clojurians (16)
- # cursive (10)
- # datomic (10)
- # emacs (13)
- # euroclojure (1)
- # graphql (4)
- # jobs (2)
- # lein-figwheel (3)
- # luminus (4)
- # off-topic (2)
- # onyx (42)
- # parinfer (23)
- # pedestal (1)
- # protorepl (8)
- # re-frame (34)
- # reagent (17)
- # ring-swagger (5)
- # timbre (24)
- # vim (72)
- # yada (1)
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?
Hi, I am curious about clojurescript. Can you we develop Mobile apps through clojure script? What should I learn to that?
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
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)It seems with
:pseudo-names true
I don’t get the extern error, while I’m using this to find the error 😛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?
@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
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.
@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!!
What’s the correct way to require cljs.spec.alpha, I suppose you need to refer-macro def
?
I'm requiring clojure.spec.alpha in a cljs and it works - why?
I get an error on this:
(s/def :foo/bar ...)
, Uncaught TypeError: M is not a function
@featalion it was a 65279 zero-width no-break space. I should have sanitized the data I grabbed from the internet. Thanx again!
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..
I am really confused at this point..with so many js options..
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.
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.
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?
If the library dynamically generates public names Google Closure will need externs IIRC.
like
var foo = {};
bar = "hello"
foo[bar] = 1
export foo;
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 originThe 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
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.
@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
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
I also don’t see what this has to do with advanced builds… but in none we get no error.
and decide to call procotol method which is most likely something completely unrelated
I would recommend compiling it in :advanced without pseudo-names but with source maps, then try to investigate exact cause
@darwin That’s exactly what I’ve been doing. With pseudo-names we don’t get the error.
@borkdude I would guess that the problem is here: https://github.com/clojure/clojurescript/blob/master/src/main/cljs/cljs/core.cljs#L1254
in your iframe x y are not identical, so it takes that protocol code path, which is somehow problematic in your case
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
look at the generated code and maybe inspect what exactly those props are and where they came from
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
AFAIK that emits window["top"]
which may not be equal to window.top
in case of native objects
cljs.oops emits window["top"]
but that will get rewritten into window.top
by closure compiler (to save 3 characters) 🙂
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
@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
its better since https://dev.clojure.org/jira/browse/CLJS-1658 but fast path protocols don’t use the sentinel
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?
It doesn’t work like that in our case (yet), but it might be a good idea to go that way.
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
generally you want to avoid even having to ask the question by never having top level side effects in the files
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
ie. the first require of the first require of the first require etc.
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
it’s simple depth first
all requires of the first require are loaded before the second require is run
it’s somewhere in the core clojure docs I assume but it’s not a complicated algo
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?
valuable?
pun(ish) intended
with the understanding that zero and Infinity are “values”
but whatevs
to me, you’re code is asking “is this thing valuable?”
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
I’ve used absent?
for a similar predicate
but returning true for 0 / nil / () etc.
or if you want false for those, I would call it present?
@rnagpal With 1.9.456 a change was made to ensure that namespaces are loaded in the order specified in the ns
form.
@mfikes wow super surprising that this was ever false - was this a cljs bug?
OK “Defect” means yes then 😄
thanks for the info
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
haha, one of those “depends on what your definition of is is” arguments
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?
I could just use (str a b)
but I feel like that might be pretty inefficient when done for large amounts of pairs?
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
as it turned out, you don't have to check if it's string to use clojure.string/blank? on it
@martinklepsch wouldn’t (hash [str1 str2])
work?
I could just use (str a b)
but I feel like that might be pretty inefficient when done for large amounts of pairs?
@martinklepsch but that would have collisions for “hel” “lo” and “h” “ello”
for example
the hash of [a b] is the same between clj / cljs
and is much harder to make collide
@noisesmith yeah, your suggestion is best I presume, didn’t think of it haha
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
@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
the ClojureScript compiler should work with Clojure 1.8
wrt. the errors, see :closure-warnings
@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!
@anmonteiro Figwheel doesn’t accept options it doesn’t know about - you need to configure it
I suspect that’s a Figwheel problem checking the ClojureScript options
^ what David said
@anmonteiro So I solved the second problem with :language-in :es5
@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
@tiagoantao this doesn’t have anything to do with 1.8
it’s not about the version of ClojureScript being used
if you have one in your dependencies, it’ll use that one
I’m trying to find the option you need for Figwheel
something about schema checks
exactly
@tiagoantao ^ add :validate-config :warn-unknown-keys
to your figwheel options
the problem should go away
or use Figwheel 0.5.11 which has :npm-deps
in the option schema
https://github.com/bhauman/lein-figwheel/blob/master/CHANGES.md#0511-new-cljs-compiler-options
@dnolen @anmonteiro This newbie profoundly thanks both of you for your wizard help. Your magic worked!