This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-04-25
Channels
- # announcements (2)
- # architecture (7)
- # aws (1)
- # babashka (105)
- # beginners (88)
- # braveandtrue (2)
- # calva (9)
- # cider (18)
- # cljs-dev (265)
- # cljsrn (22)
- # clojure (138)
- # clojure-argentina (3)
- # clojure-austin (1)
- # clojure-france (14)
- # clojure-italy (6)
- # clojure-uk (8)
- # clojurescript (283)
- # community-development (4)
- # conjure (11)
- # datomic (43)
- # docker (12)
- # duct (16)
- # emacs (1)
- # figwheel (1)
- # figwheel-main (27)
- # fulcro (10)
- # graalvm (6)
- # kaocha (4)
- # malli (9)
- # off-topic (13)
- # rdf (2)
- # reagent (12)
- # shadow-cljs (86)
- # spacemacs (1)
- # vrac (1)
i think @bhauman made a version of that with https://github.com/bhauman/cljs-test-display
Does anyone use a testing library for testing react components? Which one do you use and why?
is there a way to find the exact line number where an error occured in my cljs file? My stack trace doesn't show the line so it's harder to debug:
Error mounting card {ns: myapp.workspaces.cards-test", name: "cart-not-shown-initially-test", str: "myapp.workspaces.cards-test/cart-not-shown-initially-test", _hash: 69565119, _meta: null, …}cljs$lang$protocol_mask$partition0$: 2154168321cljs$lang$protocol_mask$partition1$: 4096name: "cart-not-shown-initially-test"ns: "myapp.workspaces.cards-test"str: "vendo.workspaces.cards-test/cart-not-shown-initially-test"_hash: 69565119_meta: null__proto__: Objectapply: ƒ (self__,args66157)call: ƒ (unused__32982__auto__)cljs$core$IComparable$: {}cljs$core$IComparable$_compare$arity$2: ƒ (x,y)cljs$core$IEquiv$_equiv$arity$2: ƒ (_,other)cljs$core$IFn$_invoke$arity$1: ƒ (coll)cljs$core$IFn$_invoke$arity$2: ƒ (coll,not_found)cljs$core$IHash$_hash$arity$1: ƒ (sym)cljs$core$IMeta$_meta$arity$1: ƒ (_)cljs$core$INamed$_name$arity$1: ƒ (_)cljs$core$INamed$_namespace$arity$1: ƒ (_)cljs$core$IPrintWithWriter$_pr_writer$arity$3: ƒ (o,writer,_)cljs$core$IWithMeta$_with_meta$arity$2: ƒ (_,new_meta)cljs$spec$alpha$Specize$: {}cljs$spec$alpha$Specize$specize_STAR_$arity$1: ƒ (s)cljs$spec$alpha$Specize$specize_STAR_$arity$2: ƒ (s,_)equiv: ƒ (other)garden$selectors$ICSSSelector$: {}garden$selectors$ICSSSelector$css_selector$arity$1: ƒ (this$)toString: ƒ ()constructor: ƒ (ns,name,str,_hash,_meta)__proto__: Object TypeError: Cannot read property 'cljs$core$IFn$_invoke$arity$1' of null
at Object.nubank$workspaces$ui$render_card [as render_card] (ui.cljs:71)
at nubank$workspaces$ui$WorkspaceSoloCard.eval [as componentDidMount] (ui.cljs:226)
at commitAllLifeCycles (react-dom.development.js:17335)
at HTMLUnknownElement.callCallback (react-dom.development.js:150)
at Object.invokeGuardedCallbackImpl (react-dom.development.js:200)
at invokeGuardedCallback (react-dom.development.js:257)
at commitRoot (react-dom.development.js:18949)
at eval (react-dom.development.js:20419)
at Object.exports.unstable_runWithPriority (scheduler.development.js:256)
at completeRoot (react-dom.development.js:20418)
@lilactown I mount the component like so, using react-testing-library
(defn mount-cart-component! []
(render ([:div {:id "cart"}]))
)
(deftest my-test
(mount-cart-component!)
;; ...
)
But I get the error repl/invoke error Error: Invalid arity: 0. Why would this be?This looks broken also unless render is a macro. It calls a vector as a function. Pretty sure you’re calling (render nil).
When I do it this way, the error disappears:
(defn mount-cart-component! []
(render (:div {:id "cart"} "Cart"))
)
But afterward doing
(.getByText screen "Cart")
I get
TestingLibraryElementError: Unable to find an element with the text: Cart.
which means render doesn't load the component to the dom. It's most likely because I'm using #workspaces? How would I mount it in workspaces then?That code is quite broken. The :div is being called as a function. It will pick the :div key out of your property map but since it’s not set it returns the second argument. So you’re calling (render “Cart”).
Using square brackets gives:
repl/invoke error Invariant Violation: Objects are not valid as a React child (found: object with keys {ns, name, fqn, _hash, cljs$lang$protocol_mask$partition0$, cljs$lang$protocol_mask$partition1$}). If you meant to render a collection of children, use an array instead.
Ah. Sounds like you need (r/as-element ...)
Reagent can wrap hiccup to act like a native react component
@lilactown, did you set up react-testing-library with jest? How do you automate testing in clojurescript when using jest+react-testing-library?>
Does anyone know if the new webpack support would offer anything over / be worth switching to from: deps.edn, figwheel-main w/ an existing webpack serving as input to the CLJS build?
Basically this: https://github.com/bhauman/figwheel-main/blob/master/docs/docs/npm.md
As you say fairly similar to preparing npm deps as a webpack and then consuming them.
But it gives you js tooling reach too. I think you can get things like storybook to consume your views. (Untested)
Others might have more compelling examples
@olivergeorge wouldn’t that “js tooling reach” be counteracted by a “cljs tooling shrinkage”? Or would it really be a “best of both worlds” scenario?
I’m hoping it’s a “cherry pick the best” type scenario!
my render function from this library doesn't load the rendered component on the dom.
No promises but perhaps this helps. https://github.com/mdxprograms/d4rkst4r-v2/blob/d7a3ac070f205aa042236a8a77ee3d59f431f9ba/src/app/hello_cards.cljs
It’s a handy trick
I wanted to use testing-library/react too, but in the context of figwheel-main, not shadow-cljs. Alas, I can't figure out how to include it in the dependencies and would need some pointers and what to look at.
I searched github for Clojure code including “testing library cljs react”
There might be better examples out there.
@johanatan the problem w/ the old way is that it was "backwards" so it created more configuration - to be honest it wasn't really that hard but it was a stumbling block. In the new way where you pass on to a JS build tool you don't need to bother with configuration at all. So fewer opportunities for user error
been trying out the latest cljs with npm stuff, good stuff... wondering how the tree shaking works, if I require a bunch of node modules in my ns, but the functions that use them are ultimately unused, will they be left out of advanced build?
@johanatan re "tool-shrinking", there's actually not that many build tools in the ClojureScript system - nothing like JS. Part of the problem is that some fundamental things need to be solved in ClojureScript first like externs inference. There are exceptions like shadow-cljs because it reimplemented stuff or fixed stuff out of tree - but that's not helping anything but shadow-cljs.
@tatut hopefully the initial docs were pretty clear on this, if you're passing onto bundler none of the node_modules
stuff is going through Closure
it's trivial to take a bundle target project and convert it to pass everything through Closure but not useful because it's not going generate stuff that will work.
(ns foo (:require ["some/npm/Stuff" :as bar])) (defn baz [] (bar/dothing)))
so if baz in the above is never called by my other cljs code and no other code touches bar, will the npm library be included in advanced build?the npm lib will be included in your JS bundle unless you use the JS tooling (webpack/rollup/whatever) to remove it
cljs/gcc won't do any DCE or module splitting of external JS code that's loaded using the new method of :bundle
target + JS tooling
Closure doesn't know what you're calling, it will never see the thing called, so it can't possibly eliminate it
(as long as it's something you've inputted to the compiler, not true for node_modules
and the bundle target)
if I understand correctly, there's possible implications for cljs library authors that rely on npm stuff on how to structure into namespaces
The guide https://clojurescript.org/guides/webpack does not work under Windows (PowerShell). I get this,
;; clj -m cljs.main -co build.edn -O advanced -v -c -s
Applying optimizations :advanced to 42 sources
Execution error (InvalidPathException) at sun.nio.fs.WindowsPathParser/normalize (WindowsPathParser.java:182).
Illegal char <:> at index 2: /C:/Users/hiadhy/Code/<snipped>
Seems to be a known issue: https://clojure.atlassian.net/browse/CLJS-2401
@dnolen if you're around, we spoke the other day about inference warnings and protocols - I've tried yesterday's release of CLJS and still unfortunately getting some warnings - is there something missing in the repro case on https://github.com/dazld/cljs-protocol-inference-warning ...?
looks like the inference warnings around defrecord
etc are gone, but the protocol itself still triggers them
Hi! I understand that CLJS's resolve
takes only a static symbol because of advanced compilation. However, I need to resolve a symbol dynamically but at compile time, I cannot manage to find how to do that
Even though it would happen at compile time? I don't believe it would result in anything bad, at least not for my use case
is there a reason cljs.analyzer/resolve-var
isn’t appropriate for resolving a symbol dynamically at compile time?
https://ask.clojure.org/index.php/8976/offer-resolving-facility-friendlier-towards-macro-authors
The ones here eg cljs.analyzer/resolve-var
give you the known information about a symbol, which can be dynamic at compile time
It just can't be dynamic at runtime
Hi, beginners question, but can't seem to find a straightforward solution for it: I'm using cljs-http to send a request to an api, but don't understand how to get the returned value out of the async channel. Within a go
block, I can call <!
and do things with the resulting response inside the go block, but I'd like to have my function return the response, rather than being forced to use it inside this go block. How do I get the go block to return the response, rather than the channel itself? I assume I'm tackling this from the wrong angle?
there isn't a blocking version of <!
in cljs - you have to use it in an async way, iirc
No experiences with promises yet (or async in general), but you're suggesting to deliver it to a promise inside the go block and deref the value when I need it?
think that's not going to be a great idea, as derefing the atom (or whatever) wouldn't give you any guarantee that the value you requested is the one that came from that particular API call
(defn some-api-call [path]
(-> (js/fetch (str " " path))
(.then (fn [r]
(if (.-ok r)
(.json r)
{:status (.-status r)})))))
(-> (some-api "uuid")
(.then (fn [response]
(js/console.log response))))
you could throw an exception if the response isn't ok
- that's up to you to handle as you wish.
Thanks for the help! Had to look into (.then ) and javascript interopt. Never done any of this. If I understand it well (probably not ...), this way I'm still tied to only being able to use my api respone within a certain "code block", here within the (.then (fn [response] ...)
call. Is there no way to create a function that calls an api, waits for the result and returns the response body so it can be used somewhere else in the code?
Disclaimer: Never done any frontend dev, so maybe this is a dumb idea.
It’s a perfectly reasonable thing to want! It’s just not how good js is written. Back in the good old days, there was a synchronous xhr call which would do what you want, but as it blocks the main thread, this isn’t really what you want in 2020.. or even in 2010.
There’s async await in recent js which let’s you write code that looks sync, but it’s still just sugar over promises.
It’s a consequence of how js works - it’s single threaded backed by a thread pool that handles io in the background, hence all the fun with callbacks
So, writing anything that is async means you have to yield to the event loop if you don’t want to block, which you don’t.
Promises are arguably a good way of dealing with this, but it does mean that all your code that extracts a value from a promise has to be chained somehow. It’s a different paradigm.
As an aside, promises are monadic in this sense, in that values have to be extracted from the wrapper, but that gives you nice properties for error handling and composition. They’re idiomatic and worth learning in js and cljs.
Ok, thanks for all the background info! I got "dragged" into this, because I wanted a small interactive webpage for a first clojure project I've been working on. So trying to cobble this together with no cljs or js experience and only a bit of clj skills, I bump into a bit more unexpected blocks then I expected.:)
In the end, I stuck to using cljs-http. I pass in my reagent atom into the function that does the api call and update the atom inside the go block with the result of <!
. Not sure if that is a good solution, but it seems to work at moment.
does anyone use use-fixtures for testing in clojurescript? How do you get it to work?
This is my test file:
(use-fixtures :each {:before (fn []
(prn "using fixtures")
)})
(deftest use-fixtures?
(is (= 1 1))
)
And while the test passes, I don't see the prnFrom a cljs codebase (simplified):
(use-fixtures :once (fn [f]
(with-redefs [something identity]
(f))))
Would you please elaborate? How do I use this with a function, say (fn [] (prn "using fixtures))?
The (sync) fixture takes the test/tests as an argument (`f`):
(use-fixtures :once (fn [f]
(print "hi")
(f)))
Have you tried using js/console.log
instead of prn
? Your test runner might not be invoking enable-console-print!
I know now why I wasn't seeing a console print. I'm running the tests through #workspaces, rather than using (run-tests). Only when using the latter, the prints work, but I would like use-fixtures to work with #workspaces too. #workspaces uses its own deftest macro
(defmacro deftest
"Creates a test card, you can replace your cljs.test/deftest call by this, will
work the same, but also define a card (the original cljs.test/deftest will also be
called)."
[sym & forms]
(let [fqsym (if (namespace sym)
sym
(symbol (name (ns-name *ns*)) (name sym)))
forms' (mapv (fn [exp] `(fn [] ~exp)) forms)
card-form &form]
`(do
(init-test '~fqsym ~forms' '~card-form)
(if-cljs
(cljs.test/deftest ~sym ~@forms)
(clojure.test/deftest ~sym ~@forms)))))
But that doesn't make a difference. It's just that the prints don't show in the console when running the tests in workspaces.> I'm running the tests through #workspaces I'd give that channel a try then. Are you able to see fixtures operating properly outside workspaces?
I have the following use-fixtures defined in my test file:
(use-fixtures :each {:before (fn []
(prn "using fixtures")
) :after #()})
But running none of the tests in this file prints "using fixtures"Hi what do you guys use for JWT? https://github.com/funcool/buddy seems to be very old and not taken care of
i've used that at a previous job. i don't believe jwt's have changed in the meantime. it served my purposes fine and is maintained by some security conscious people as far as i know. but those are jvm based i believe so not suitable for cljs
wasn't there a ticket to have and nevermind it works. i thought i had checked it recently.cljs.repl/{doc,dir}
work on GCL? so you could call dir on goog.events and similar? I looked in jira and not finding it and wonder if i'm misremembering?
Can someone help me with externs? I wrote this code to improve on the datatables recipe: https://pastebin.com/PxPinWKw. After setting infer-externs
& `warn-on-infer` I get these warnings: https://pastebin.com/nwdFJSZQ.
My understanding is that I'm supposed to provide type hints, but I don't know how to determine the types I'm supposed to hint eg "what is .destroy a member function of?"
Additionally, I recompiled the namespace with *warn-on-infer*
and these warnings went away. Does that mean an externs file has already been generated? Where would it be located?
i've overhauled inf-clojure so that the experience is extremely nice with just the raw cljs.main and i'm loving it. so thanks for prodding me on that. and i'm looking forward to it. thanks for all your work!
How does it compare with cider and shadow-cljs?
not as full featured. shadow can run an nrepl server so all the CIDER goodies apply. inf-clojure is super nice if you want to run simply clojure -m cljs.main -r
It was prompted when i wanted to follow along with the new bundle target for clojurescript
it puts you back at the classic repl experience of editor that can easily send commands to a running repl
I have been using Chlorine Atom for 4 to 5 months, was using cider and emacs before that, now coming towards cider again with doom emacs.
Any Suggestions, recommendations, advices?
I am building application using Fulcro/Pathom and PostgreSQL.
inf-clojure is not nearly as full featured and if nrepl works its clearly the way to go
stuff like this https://github.com/google/closure-compiler/blob/master/externs/browser/w3c_dom3.js#L102-L110
One way I thought of would be to save eg this
in an atom and log it to the console in order to divine the type
that just gives me the render function. pretty sure that doesn't factor into externs
It looks like the warnings are still getting printed to the js console, just not in my repl
@dpsutton glad to hear inf-clojure + cljs.main works well! that was my preferred Emacs setup
it would parse that info to emit warnings similar to WARNING: cljs.core/+, all arguments must be numbers, got [string number] instead at line 1 <cljs repl>
?
that sounds quite nice. i'm really digging the thoughful run-time documenting aspects of clojure. gonna have to go vote on that javadoc ticket for clojure 1.11
a bigger project to think about is seeing if we could reconcile fns specs w/ the interop barrier
instead of polluting our code w/ types we could just use the fnspecs and compare against the externs
this would get you at least Common Lisp level basic checking which is still reasonable - could be REPL friendly too
anyways - this not something I'm planning on working on in the very near future - but it's been in the back of my mind for a long time
we used to use Closure type checking, but I could not make it do what I wanted and it was not usable during REPL dev, only advanced
the type inference is getting good enough where this new line could be reasonably explored
REPL friendly type assistance would be pretty cool - not so common a feature in languages
not a huge fan of TypeScript, but I understand that having some type checking is flat yes/no for some people assessing technologies
I think having the option to check specs against inferred types and externs would draw those kinds of users in
by fnspecs do you mean cljs.spec fdefs, or are fnspecs something I haven't learned about yet?
Is there anything like (type thing)
in cljs which gives me the information needed to include type hints? type
works in clojure for this purpose but apparently not clojurescript.
To try this a third way, the externs guide (https://clojurescript.org/guides/externs) teaches you to type hint in order to produce externs. @dnolen goes through an example where he type hints `wrap-baz` with `^js/Foo.Bar`, but doesn't show me how he determined that `^js/Foo.Bar` is the type hint which was needed. How did he do that?
Thank you!!! I'll give ^js
a try and see if that removes the inference warnings
has anyone used jest with clojurescript? How did you install it? After I install it using npm install jest and add "test":"jest" in package.json, I expect keywords like "expect" to work:
(.toBeInTheDocument (expect (.getByText screen "Some Component")))
But I get that expect is undefined. js/expect gives undefined as well. How to get jest to work with clojurescript?I have experimented with it. Here is the repo https://github.com/athomasoriginal/demo-clojurescript-jest
How did you install it exactly? The documentation doesn't explain very clearly. Is there a reason why you only experimented with it and not use it regularly?
> How did you install it exactly?
This is covered in the https://github.com/athomasoriginal/demo-clojurescript-jest#quickstart guide. The idea is that Jest is such an NPM package, so it’s installed when you run yarn
and then the webpack stuff is just what’s outlined in this guide: https://clojurescript.org/guides/webpack (or rather than guide before the awesome new CLJS that came out).
Then you build your tests, and then you run yarn against your compiled tests
> Is there a reason why you only experimented with it and not use it regularly? Yes. Part of the reason is I just didn’t find this worth while enough to keep pursuing. It would be cool to continue exploring at some point even if it was just to provide an example to the CLJS/JS community about how it can be done. The reasons though: • There is a performance cost while running the tests • The developer experience will require some work to get everything in a similar state to using Jest w/ JS • Most importantly, the cljs ecosystem provides most of the functionality and with a little elbow grease, you can get most of the same functionality Jest provides with CLJS libraries.
Cider has a great one @ https://github.com/clojure-emacs/cider/blob/052290d080f58edc814dd7aa00b014d639c62974/cider-test.el, but it doesn't work with cljs.
> Have you found a good test-runner for cljs? Yeah, so it depends what you want out of your “test-runner”. I would like to experiment with https://github.com/lambdaisland/kaocha-cljs, but right now I just write my own and tack on additional libraries as I need. an example of the simplest form of my setup: https://betweentwoparens.com/clojurescript-test-setup
But to expand on the original question of why not jest and how clj/cljs provides what I need. Jes is • test runner • test environment • assertion library • reports • special tests (SNAPSHOT) • etc Then it just wraps them together.
• test-runner is pretty easy to implement a basic one - kaocha would be a better one
• clojure.test takes care of assertion
library and such
• The test environment is just JSDOM - see the blog post attached above
and anything else like improved reporting, is pretty easy to cobble together from the CLJ/CLJS libraries available.
> why not keep using kaocha-cljs? Why write your own toolchain? Oh, don’t get me wrong, I want to use kaocha, or just another test-runner, but I just haven’t had an opportunity to stetup yet
My main point is that each of the things that Jest gives you is pretty easy to setup and you get the full clj/cljs experience
Say I need to find if a button contains a piece of text [:div [:button {:on-click #()} "Continue"]]. What would a function look like to test that?
And to give an example of what I test: • vanilla cljs code in browser and in our ci-environment (thanks, JSDOM!) • react components/screens - anything you like
Yeah, so for that you can use the excellent react-testing-library
and it might look something like this:
(deftest test-button
(let [button-click-count (atom 1)
left-click {:button 0}
handle-button-click #(swap! button-click-count inc)
button [button/button
{:on-click handle-button-click}
"My Button"]
container (test-library/render mounted-containers button)
button-elem (.. container (querySelector "button"))
text-elem (.. rts (getByText container #"(?i)my button"))]
(testing "button text wrapped in span"
(is (= (-> text-elem .-tagName string/lower-case) "span"))
(is (= (-> text-elem .-textContent) "My Button"))) ...
of course, you need to setup your app to use react-testing-library
which is part of the JS ecosystem and for that checkout the webpack
guide I posted above
And also note that I have not included the setup/teardown functions. That’s what test-library/render
is. It’s something I wrote really quickly. This means you have to track whats added to the DOM so you can remove them when the tests are done….otherwise you will have multiple elements attached at any one time
Yeah, I am already using the react-testing-library. How do I include the setup/teardown functions to automatically run for each deftest?
That is just how clojure.test
does things. e.g.
(use-fixtures :each
{:after #(cleanup-containers mounted-containers)})
I will eventually write this stuff up in a proper document
Yeah, I mean, when you begin to piece together what JS is doing and a bit of how CLJS is working it’s surprising how much is already available in the CLJ/CLJS ecosystem
Then, once yous solve your problems, as I have done in my own tests, you don’t need much more. The things I want now is just a better DX, aside from that, things work pretty well
Nothing big enough to really address here. Just subtle things that would improve my personal workflow.
Also keep in mind that I like spartan setups in general, so my approach may not be great for everyone…but it does cover most all the things
Example of things I can do without: snapshot tests. I don’t really see much value in them, but that is a point that many will argue with 🤷
I think there are certain things as well that could be improved in my workflow, but some of them are subconscious
or that I've gotten used to them and forgotten that they are a source of inefficiency
So I added [lambdaisland/kaocha-cljs "0.0-71"] in my project.clj and ran
clojure -m kaocha.runner unit-cljs
but got
Could not locate kaocha/runner__init.class, kaocha/runner.clj or kaocha/runner.cljc on classpath.
Any ideas why?You have both lambdaisland/kaocha
and lambdaisland/kaocha-cljs
?
what does your deps.edn look like? and you have a test.edn file?
it works now. I didn't have the bin/kaocha set up. I think that's why it wasn't working before
But now I get the following error: No such namespace: @testing-library/react, could not locate CIRCAtesting_library_SLASH_react.cljs, CIRCAtesting_library_SLASH_react.cljc, or JavaScript source providing "@testing-library/react" (Please check that namespaces with dashes use underscores in the ClojureScript file name) in file /Users/...
Although I have testing-library required in this file: ["@testing-library/react" :refer (render fireEvent waitFor screen cleanup)]
your using webpack, figwheel, shadow?
not sure off the top of my head.
@U6GNVEWQG Maybe this is relevant
@U6GNVEWQG you mentioned testing with jsdom. Why do you like testing using jsdom?
@dnolen I added ^js type hints to three of the member accesses and I am still seeing inference warnings. https://pastebin.com/A7cbdjGB
Um, ew.
(defn home-did-mount [^js this]
(.DataTable ^js/$
(js/$ ^js (.-main ^js (.-refs ^js this)))
(clj->js
{:columns columns
:data data
:responsive true})))
It does seem to get rid of the inference warnings around this function. I had to use ^js/$
for that second one, though.
I have :infer-externs
on in my cljsbuild config, but only for building the uberjar.
@doubleagent you should only need to do it once for this
, are you using 1.10.741
?
@dnolen I'm on 1.10.597
there some externs issues with 597, but anyways, what warnings do you get with only hinting the fn arg on 597
Figwheel: Compile Warning - Adding extern to Object for property refs due to ambiguous expression (. this -refs) in file src/cljs/bigboard/core.cljs at line 381, column 4
Figwheel: Compile Warning - Adding extern to Object for property main due to ambiguous expression (. (.-refs this) -main) in file src/cljs/bigboard/core.cljs at line 381, column 4
Figwheel: Compile Warning - Adding extern to Object for property DataTable due to ambiguous expression (. (-> this .-refs .-main js/$) DataTable (clj->js {:columns columns, :data data, :responsive true})) in file src/cljs/bigboard/core.cljs at line 380, column 3
@doubleagent see #figwheel-main
@nathan.probst this is not a figwheel issue it's ok
@doubleagent what is the type of that argument, you must know since you're getting it from somewhere
I think it's a React.Component
, but honestly I don't know because reagent hides a lot of that stuff from me.
I'll try that.
@dnolen that reduces the warnings to one.
Figwheel: Compile Warning - Adding extern to Object for property DataTable due to ambiguous expression (. (-> this .-refs .-main js/$) DataTable (clj->js {:columns columns, :data data, :responsive true})) in file src/cljs/bigboard/core.cljs at line 380, column 3
Using :target :bundle
and using the dependency "chart.js"
, which has a non-valid clojure name and returns its constructor, what would be the sensible way to deal with that? I see that it’s possible to use an alias in package.json so you can call it something like "chartjs"
. But how about usage? You can’t run the alias as a constructor:
(require [chartjs])
(chartjs. params)
@doubleagent same problem, what is the type of the thing with DataTable
method?
Beats me. It's whatever jquery's $
function returns when passed an HTMLTableElement
Do I need to go read the jquery source code in order to figure it out?
jquery documentation says it's a collection, but maybe it collapses the colletion when there is only one matching element.
I'll try ^js/HTMLTableElement
That didn't work.
(defn home-did-mount
[^js/React.Component this]
(reset! x this)
(.DataTable
^js/HTMLTableElement
(-> this .-refs .-main js/$)
(clj->js
{:columns columns
:data data
:responsive true})))
Figwheel: Compile Warning - Adding extern to Object for property DataTable due to ambiguous expression (. (-> this .-refs .-main js/$) DataTable (clj->js {:columns columns, :data data, :responsive true})) in file /c:/Users/doubl/OneDrive/Documents/GitHub/bigboard/src/cljs/bigboard/core.cljs at line 384, column 3
@doubleagent ok this one I think is fixed by 1.10.741
@dnolen my understanding was that it would break under advanced compilation
Ah, okay. My mistake.
the warning just says it doesn't know what the type is so it's creating an extern on Object
Alright, thanks
@ingesol I looked at the analyzer - it seems like it should work - but you didn't really give enough information about what didn't work for you
also you don't need to bother with the alias in package.json
, (:require ["chart.js" :as chart])
should work
@dnolen oh, I just assumed that those things were specific to shadow-cljs. It probably works then, sorry for the confusion
@ingesol the semantics of shadow are subtly different and should never be relied upon in code you intend to publish (as a library)
in shadow-cljs I believe string requires means it's a JS module, not true for ClojureScript
we had to solve that problem way back when we did all the work to push everything through Closure
in the end while the bundler stuff appears to be big news, it was really minor changes to tie together the work of the past 5 years
I guess in theory, if your npm deps can go through Closure, that might still be beneficial to go that route for those and get the benefit of dead code elimination
it should… is there an issue you’re running into?
Cool! Not yet. I just couldn't remember if it was tied to Java's IO. It also wasn't listed in http://cljs.github.io/api/cljs.core/ as far as I could tell.
weird. it doesn’t seem to be included, but there’s no reason you couldn’t write the macro to work in cljs
Ah yeah, found an example. http://clojurescriptmadeeasy.com/blog/cljs-read-files-line-by-line-on-nodejs-part-2.html which makes me think it's likely not included.
yea. doesn’t seem to be
but, conceptually, it seems like there’s no reason it couldn’t work. I guess .close
is a less common interface in js than on the jvm (although there are examples like websockets)
¯\(ツ)/¯
in general IO is completely different in JS - some environments don't have access to the file system, and most IO is async so with-open
doesn't make nearly as much sense
I am no expert but I read about the two phase evaluation of CLJS. The first phase happens in the JVM, the second phase happens at runtime in whatever environment you are targetting. I would think with-open can work normally in the first phase. You can read the file ahead of time and cache the contents. If you want to read the file at runtime, then you must rely on the functionality available in the target environment.
I'm following the webpack guide, but noticed that with -r and -v option the repl doesn't appear in the console until I press enter. the initial output for the repl is injected somewhere in between the output
More less expected with -v output I’ll probably remove that, it just makes it easier to know that some is happening