This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-11-19
Channels
- # bangalore-clj (1)
- # beginners (8)
- # boot (102)
- # cider (1)
- # clara (14)
- # cljs-dev (2)
- # cljsrn (2)
- # clojure (49)
- # clojure-poland (3)
- # clojure-russia (4)
- # clojure-serbia (1)
- # clojure-spec (5)
- # clojure-ukraine (1)
- # clojurescript (181)
- # core-async (4)
- # cursive (2)
- # datomic (7)
- # dirac (34)
- # figwheel (3)
- # fulcro (21)
- # hoplon (5)
- # om (1)
- # parinfer (4)
- # planck (27)
- # re-frame (30)
- # reagent (11)
- # rum (6)
- # shadow-cljs (22)
- # spacemacs (4)
- # unrepl (26)
I've got a cljs.test failing. It's a simple (is (= a b))
test, and the Actual
output shows no difference. Like I literally copy-paste the Actual
into a repl and it returns true
.
Fail (thrower) (com/grzm/dev/cljs_stacktrace/util_test.js:1269:51)
Expected (= first-file-expected first-file-actual)
Actual: (not (= "resources/public/js/compiled/out/test/com/grzm/dev/cljs_stacktrace/helpers.cljs" "resources/public/js/compiled/out/test/com/grzm/dev/cljs_stacktrace/helpers.cljs"))
I'm tempted to say types (but I don't think that makes sense)? have you tried ==
instead of =
?
Yup. Same result. (btw, I think ==
is just for numerical comparisons, as I understand it. http://clojuredocs.org/clojure.core/==)
I've also checked (= (meta a) (meta b))
, and that succeeds (just trying to cover all my bases)
maybe (= (str first-file-expected) (str first-file-actual))
??
(clutching at straws...)
yeah, I can get lonely on this channel... I think I must be in the wrong timezone of something...
@noisesmith I appreciated your help earlier with the stateful component question above. I thought through this for a while and came up with another alternative based on your idea I'm going to start using. This lets me create reusable stateful components without always needing to know the state-shape the component expects. here's a gist: https://gist.github.com/zakpatterson/4df511752b4f53d23deef4de309644c3
yeah, 1PM
so @grzm, what are you comparing exactly? are they file objects? can you get the absolute paths?
and you're pulling out the first map from the vector... :thinking_face:
Yeah. The higher level (which is also failing, of course), is (vec (take 2 stacktrace))
. Trying to dig down to see what's different, I'm comparing the values of the maps. That filename value is what's failing the equality test in each frame.
so that file value can't possibly be a simple string, right? otherwise the test would pass? odd... what could it be?
That's a good idea…
Expected (not= (type first-file-expected) (type first-file-actual))
Actual: (not (not= #object[String] #object[String]))
well, that's frustrating... how about using clojure.string/includes?
i.e. (and (includes? first-file-actual first-file-expected) (includes? first-file-expected first-file-actual))
maybe there's a \ff
or \cr
in there...
I'm thinking you need to use hexdump
Yeah, that's a good idea. There's definitely some extra characters there. The counts are different.
maybe just use trim
and be done with it
really, that would seem to be a greater mystery
what, like a golang slice? I don't think so!
I was thinking more like a Java bytebuffer, but yeah, neither should be the case in cljs
that would seem very un-clojure... but you know: javascript!
that's both the problem and one of cljs best selling points: you can't get away from the host system
so the diff of the counts is 5?
or is there like 5 backspaces so that the string prints that way?
Yup. There's a goog.string.StringBuffer class used in str
: https://github.com/clojure/clojurescript/blob/master/src/main/cljs/cljs/core.cljs#L2923-L2935
how about
(is (= (class a) (class b)))
(is (= (count a) (count b)))
(is (= (str a) (str b)))
?perhaps (seq a) (seq b) would be revealing, even if they print the same as one another
count
are different, str
is different, type
is different. and yeah, I used seq to reveal the "base/"
at the beginning of one of actual
.
hmm, so you can use str
in your test?
or just put "base/"
in your expected string? You have this solved, right?
(I didn't think so)
type is better regardless
Here's a summary of what I'm looking at:
Fail (thrower) (com/grzm/dev/cljs_stacktrace/util_test.js:2367:51)
Expected (= first-file-expected first-file-actual)
Actual: (not (= "resources/public/js/compiled/out/test/com/grzm/dev/cljs_stacktrace/helpers.cljs" "resources/public/js/compiled/out/test/com/grzm/dev/cljs_stacktrace/helpers.cljs"))
Fail (thrower) (com/grzm/dev/cljs_stacktrace/util_test.js:2367:51)
Expected (= (count first-file-actual) (count first-file-expected))
Actual: (not (= 84 79))
Fail (thrower) (com/grzm/dev/cljs_stacktrace/util_test.js:2367:51)
Expected (= "" first-file-actual)
Actual: (not (= "" "resources/public/js/compiled/out/test/com/grzm/dev/cljs_stacktrace/helpers.cljs"))
Fail (thrower) (com/grzm/dev/cljs_stacktrace/util_test.js:2367:51)
Expected (= [] (take 10 (seq first-file-actual)))
Actual: (not (= [] ("b" "a" "s" "e" "/" "r" "e" "s" "o" "u")))
that's so strange, but if you use (= first-file-expected (str first-file-actual))
then it passes?
because goog.string.StringBuffer is doing something strange?
I mean, yes, that's good
Expected (= (str first-file-actual) (str first-file-expected))
Actual: (not (= "resources/public/js/compiled/out/test/com/grzm/dev/cljs_stacktrace/helpers.cljs" "resources/public/js/compiled/out/test/com/grzm/dev/cljs_stacktrace/helpers.cljs"))
try (= (str "base/" first-file-expected) (str first-file-actual))
or change your def of first-file-expected
or just (= (str "base/" first-file-expected) first-file-actual)
yes, I agree
but you might have to take that up with the Google Closure folks 😕
you could have a race condition... goog.string.StringBuffer is mutable 😞
My test assertion looks like: (is (not= (str first-file-actual) (str "base/" first-file-expected)))
(using not=
so I can see the failure results)
The failure results look like:
Expected (not= (str first-file-actual) (str "" first-file-expected))
Actual: (not (not= "resources/public/js/compiled/out/test/com/grzm/dev/cljs_stacktrace/helpers.cljs" "resources/public/js/compiled/out/test/com/grzm/dev/cljs_stacktrace/helpers.cljs"))
wait, why does "base/" just disappear?
oh... it's disappearing on the expected value? I thought it was the other way around... 😕
wait it even disappears in the first line of output...
it's like the output is piped through sed /base\//s///
😆 I don't blame you
I'm now thinking there's something else in your toolchain that's wreaking havoc
the toolchain is the worst part of web dev 😞
Yeah. One of the things I'm trying to do here is ensure portability. Toolchain improvement is actually my goal.
hey, maybe if you look at something else for while you'll come back to it with a fresh perspective, here is the problem I'm facing 😉
I'm attempting to use https://github.com/jasondavies/d3-parsets in a project... but I get this error from boot cljs
:
java.lang.IllegalArgumentException: Duplicate module path after resolving: /home/corin/Projects/Demos/boot-parsets/node_modules/d3/d3.js
I've created a minimal project: https://github.com/au-phiware/boot-parsets...when I google the error, I get the source code the emits the error... I hate it when that happens
What else do you have on your filesystem besides the repo? From a fresh checkout, when I run boot cljs
I get a different error: SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode
oh... um, let me try a clean
I don't get a SyntaxError from a clean repo... I've built clojurescript from master in the past... maybe it's that...
I tried blowing away ~/.m2/repository/org/clojure/clojurescript
but still no SyntaxError
is it complaining about es6/d3/parsets.js
?
It looks like it's higher up than that:
Writing main.cljs.edn...
Compiling ClojureScript...
• main.js
[eval]:1
let fs = require('fs');
^^^
SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode
what? eval? I don't know where that comes from
what's your boot version?
I got 2.7.2
boot -V
#
#Sun Nov 19 14:45:07 AEDT 2017
BOOT_CLOJURE_NAME=org.clojure/clojure
BOOT_CLOJURE_VERSION=1.8.0
BOOT_VERSION=2.7.2
I haven't compiled cljs with boot, though, so there might be something else wrong with my setup.
λ boot -V
#
#Sat Nov 18 21:51:17 CST 2017
BOOT_CLOJURE_NAME=org.clojure/clojure
BOOT_CLOJURE_VERSION=1.9.0-RC1
BOOT_VERSION=2.7.2
it looks like nodejs...
do you get
Classpath conflict: org.clojure/clojure version 1.9.0-RC1 already loaded, NOT loading version 1.8.0
when running boot cljs
?I tried BOOT_CLOJURE_VERSION=1.9.0-RC1 boot cljs
but I don't get SyntaxError...
v6.9.4
ok, so cljs is trying to npm install
and can't
wow... how do I specify the node version in my project config... it's the toolchain again!
so, you get the same error as me now?
oh, fair enough
one thought I had was that there were multiple inclusions of d3 in node_modeules, but I see only one.
yeah, often you get a node_modules dir inside other modules, but that thought didn't get me anywhere
The comment in the closure-compiler near that error is // Having root paths "a" and "b" and source files "a/f.js" and "b/f.js" is ambiguous.
https://github.com/google/closure-compiler/blob/master/src/com/google/javascript/jscomp/deps/ModuleLoader.java#L275
Looking at the project:
λ find . -name "d3*"
./es6/d3
./node_modules/d3
./node_modules/d3/d3.js
./node_modules/d3/d3.min.js
./node_modules/d3/src/d3.js
hmm, fair comment, changing the name of the namespace has no effect 😞
rename es6/{d3 => }/parsets.js
I feel like I need to throw in a lot of println into ModuleLoader.java....
ok, I'm doing it, I'm building com.google.javascript/closure-compiler-unshaded off master
good luck 🙂 An alternative would be to try lein. I think there are examples using d3 out there.
I know! I'm converting a project from lein to boot... I had it working with lein but for some reason it broke... I'm deep in the rabbit hole now!
Hi. Are there any well-known pointers available on the Internet on how to create a library targeting both Clojure and ClojureScript?
I have found that most examples and tutorials about cljs that have a server side component use Clojure (on the server side)
have you seen https://github.com/magomimmo/modern-cljs?
chapter 11 discusses the use of Clojure on the server
@au-phiware I guess the Modern-CLJS approach is too web heavy for me, and I am looking for ways to test the library under both CLJ and CLJS.
oh, I see, I've been focused on web, so I haven't come across any
so, your looking for cljc centric resources?
yes, CLJC with occasional CLJ and CLJS dependency for platform-specific bits
Is there a way to require macros in CLJS so that I can refer them namespaced? E.g. (foo/bar :baz)
— bar
is a macro here.
If I do (:require-macros [myapp.foo :as foo])
, then I can no more refer to functions in foo
?
On most cases you don't need to use :require-macros
, :refer-macros
, just just macros like they were functions
Oh, never knew that! Thanks for sharing that tip.
On most cases you don't need to use :require-macros
, :refer-macros
, just just macros like they were functions
@kumarshantanu See the Implicit macro loading:
section of (doc ns)
. Also see more exposition at http://blog.fikesfarm.com/posts/2016-03-01-clojurescript-macro-sugar.html
Thanks!
I have a small spec-serialize library I only use myself, where almost everything is in one core.cljc file, using (ns spec-serialize.core (:require [#?(:clj clojure.spec.alpha :cljs cljs.spec.alpha :default clojure.spec.alpha) :as s])) then a few small .clj and .cljs files witch use specific code, and call a function on the core.cljc.
@gklijs You can simplify your ns
form to
(ns spec-serialize.core
(:require [clojure.spec.alpha :as s]))
See Auto-aliasing clojure namespaces:
in (doc ns)
and some exposition at http://blog.fikesfarm.com/posts/2016-07-03-clojurescript-clojure-namespace-aliasing.htmlYou just need to ensure that the clients of your library are on ClojureScript 1.9.198 or later.
Yes for now, At least I want to add some tests for clojurescript, and some clean-up and especially documentation, then maybe put it on githup/clojars.
Inside a defmacro
, is the reader conditional supposed to always favor :clj
? E.g. (catch #?(:clj Exception :cljs js/Error) e# (println e#))
"always" in your question is pretty tricky, think about self-hosted clojurescript where defmacro
is actually cljs code
I don't remember the answer, but you should think about these corner cases if you want your library to be 100% portable including self-hosted
@darwin I’m using ClojureScript, not self-hosted one for now. (Digging into a puzzling error that complains: ReferenceError: java is not defined
in CLJS)
I could imagine some clojure macro to be unaware of clojurescript and generating some lower-level java interop code. When you use this macro in clojurescript, it will happily spit such java-interopy code in the middle of your cljs code.
OK, so I was hit by the issue described here: https://groups.google.com/forum/#!topic/clojure/DvIxYnO1QLQ and here: https://dev.clojure.org/jira/browse/CLJ-1750 — fixed it with the (:ns &env)
hack, but not sure if that’s supported by self-hosted CLJS. @darwin
my codebase's tests use with-redefs extensively, suite breaks with :advanced wherever w-r is used
I get errors in the form $my$namespace$blah$$.$cljs$core$IFn$_invoke$arity$1$ is not a function
@kumarshantanu I'm sorry at some point I knew all the details of this, but I unloaded it from my brain... cannot help ATM
No problem! Thanks for the pointers.
@vemv I'd suggest trying :static-fns false
with :advanced
to see if it might work for your case
@vemv with-redefs
is involved in a couple of compiler unit tests that run under :advanced
, but none of them attempt to redefine a function (especially a multi-arity or variadic function)
@mfikes :static-fns: seems to have fixed it, thanks! 🍻 (can't be 100% sure, as suite now remains broken for new unrelated reasons)
hi 😄 I am having trouble getting figwheel to work 😞 Figwheel compiles my js and starts but it reports Resource not Found when I try and connect
Aha, I see, I did not actually start the clojure-backend that generates the HTML page.
om, reagent or re-frame, with which one should i start considering i'm just starting with ClojureScript?
from just taking a look over the README.md in these projects they seem to be the same thing, interfaces to React from ClojureScript
from my understanding om and reagent are independent projects that both attempt to provide a idiomatic clojure interface to react, and re-frame builds upon reagent
fwiw I chose reagent when faced with the same choice as I felt that api was simpler
@zignd I assume you have a javascript background, so will explain in those terms:
reagent
wraps React
rum
wraps React
re-frame
adds a redux-ish capabilities to reagent
fulcro
is om.next
made easier. It wraps React, plus provides a client<->server story.
@zignd I would suggest you start with reagent
, kick some easy early goals. Feel good about progress, and then consider next steps from that platform.
(but I am a bit biased, so listen also to others :-))
I was going to mention om.next but I have found it very hard to find resources for it... good to know that fulcro exists 🙂
thanks @au-phiware and @mikethompson, i think i will start with reagent as both of you recommend, and because its API seems more Clojure like and less JavaScript interop than Om, at least from what i could grasp by just checking their docs quickly, and i didn't know fulcro existed
If you do choose the reagent path, then look carefully through these "Domino 5" resources: https://github.com/Day8/re-frame/tree/master/docs#domino-5
(ignore the rest of that page, it relates to re-frame)
@au-phiware figured out the mystery of the missing "base/"
: it's stripped from output by the doo reporter: https://github.com/karma-runner/karma/issues/1706
unreal... I ended up finding a bug in cljs compiler with my issue, I even filed a patch... it was late at night so I won't be surprised if it gets rejected at triage!