This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-08-12
Channels
- # beginners (49)
- # boot (2)
- # cider (62)
- # clara (3)
- # cljdoc (5)
- # cljs-dev (7)
- # cljsrn (2)
- # clojure (68)
- # clojure-spec (23)
- # clojure-uk (4)
- # clojurescript (172)
- # conf-proposals (8)
- # core-async (1)
- # cursive (1)
- # datomic (12)
- # duct (1)
- # figwheel (22)
- # figwheel-main (11)
- # fulcro (23)
- # hoplon (9)
- # jobs-discuss (13)
- # lambdaisland (3)
- # lein-figwheel (119)
- # off-topic (43)
- # onyx (1)
- # re-frame (18)
- # ring (1)
- # shadow-cljs (120)
- # tools-deps (4)
I'm surprised/confused by the source
argument to cljs.build.api/build
. It takes one source path but I have many. In cljs.main it's set by resolving the source path of the :main
namespace. I can do this although that's different between dev & prod environments which makes it an extra thing to twiddle... Is it really needed? How is it used?
Ah, you can pass a vector. The doc string An optional source parameter may be provided.
and the cljs.main example led me to conclude that wasn't the case. source
needs to implement -find-sources
(defprotocol Compilable
(-compile [this opts] "Returns one or more IJavaScripts.")
(-find-sources [this opts] "Returns one or more IJavascripts, without compiling them."))
There are other examples in the cljs.build.api where a compilable is passed in. The docstring for them is more sensible to me, for example:
compile
function
Usage: (compile opts compilable)
(compile state opts compilable)
Given a Compilable, compile it and return an IJavaScript.
Perhaps the build function should match this.@bhauman May I please contact you via DM? I want to start contributing to figwheel/core and need some help in getting started.
@bhauman I isolated the problem and I am on my way to fix it 🙂 The problem is that figwheel_server.clj tries to parse the data and in the data there is #js literal. My question is how can I parse it to map when using clojure?
Imo I should slice the string to not contain #js but maybe you got better solution.
Hello, I'm using core.async cljs and can't figure out why the x function blocks when it tries to put true in the txt-chan
(defn x
[txt-chan]
(go
(if true
(do (prn "a")
(>! txt-chan "true"))
(>! txt-chan "fail"))))
(defn x-caller
[]
(go (let [y (<! (x (chan)))]
(prn y))))
x should return the txt-chan
Could you please change the names of vars and fns? It's hard to follow it
yeah seems x returning txt-chan fixed it but I don't see why. One sec let me rename vars
The thing I can guess it the go block executed in another thread and the one that called it never took the result
Ok let me examine your code closer
Please correct the names to let me just copy and paste your code then I would love to help you 🙂
(defn child
[txt-chan]
(go
(do (prn "starting to put text in the channel")
(>! txt-chan "true")
(prn "finished putting text in the channel")))
txt-chan)
(defn parent
[]
(go (prn (<! (child (chan))))))
@urbanslug one thing to be aware of is that you are using an unbuffered (chan)
which means that the put >!
only completes when something else takes it.
The problem is that go returns the channel. It returns the last evaluated body which is (prn "finished putting text". Since putting nil on channel is an error than it's impossible to prn <! (child (chan))
Yes that's the whole problem because as I said the go returns it's own channel
which has the value of the last body
Let me check it one more time
I want to be 100% sure 😛
@urbanslug 1. only (put! channel nil) returns an error so there is no error in your code 2. @thheller it 100% right. You are putting sth into the channel but since there is nothing which can take from the channel then the code blocks 3. But why there is no take? Because: 3.1 go returns it's own channel 3.2 you do not return the txt-chan therefore the take is done on channel returned from go and txt-chan still has some value which is not taken 😛 That why it blocks. @thheller Could you please confirm?
@thheller so it blocks?
Now I am confused a little bit
(defn child
[txt-chan]
(go
(do (prn "starting to put text in the channel")
(>! txt-chan "true")
(prn "finished putting text in the channel"))))
(defn parent
[]
(go (prn (<! (child (chan))))))
Sorry for messing things up. I think that txt-chan blocks but in go block. Therefore prn does not prints "finished putting text in the channel"Nope it won't. Question is: Why it won't?
Sorry :face_palm: without returning txt-chan
Ok thank you for the clarification 😜 Sorry one more time for messing the examples 😛 @urbanslug I think that you got the answer now 🙂
hi guys
when i try this i got the error:
TypeError: (intermediate value).ih is undefined
what is it meaning?
@abdullahibra that is about missing externs and the hide
fn call getting renamed
@thheller what actually i'm trying to do is using dateDropper plugin within my app: https://felicegattuso.com/projects/datedropper/
i got jquery hide function working properly now
that's the code
for using datedroppper which is jquery plugin
can anybody help me in this?
by trying jquery hide function, i'm sure jquery is loaded successfully globally
@thheller can you help ?
@abdullahibra what do you need help with?
i'm trying to use dateDropper inside my code but failed
and what i have done so far is: https://clojurians.slack.com/files/U145X0BPE/FC71H6JBD/-.js
@lilactown that's what i have tried
do you have any suggestions ?
TypeError: $(...).hh is not a function
that's what i got
it's working correctly
but not working with .dateDropper
:foreign-libs [{:file "resources/public/js/date/datedropper.min.js" :provides ["ui.datedropper"]}]
then using (:require [ui.datedropper]) in the ns i want to use functions at
globally
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
in base.html
so it's available using js/$
WARNING: Adding extern to Object for property dateDropper due to ambiguous expression (. (js/$ "#hello") dateDropper) at line 42
referred line: [:input {:placeholder "input..." :on-change #(.dateDropper (js/$ "#hello"))}]
WARNING: Adding extern to Object for property hide due to ambiguous expression (. (js/$ "#hello") hide) at line 42
and it's working
what do you mean with externs file?
an externs file helps the Closure compiler know what external JS you have in your project so it can optimize correctly
so it can work without optimization true?
ah ok
i'll try dev mode now
@bhauman I am here if you want to discuss further that figwheel parsing problem. 🙂
so if the problem is a problem with reading a clojure string you don't want to adhoc change the string
If you prefer communicating via Github then I don't mind 🙂
Yes you got right.
Did not want to overhelm the ticket with to much information
I edited my comment
So as you can see it's not a problem with the #js
it's a problem that the parser tries to evaluate (or read ((clojure noob here, don't punch plx))) the #object #js as reading macros
You mean edn/read-string
yea but how the Clojure parser can know what #js means. It means something in Clojurescript environment not in Clojure env
Ok sorry let me read that
@kwcharllie379 you also don't seemed to have responded to me stating that figwheel.main has the exact same edn/read-string
and so I'm very suspicious about what is going on here
Let me check that again
I am trying to see what it would look like to write CLJS tests with Jest. The problem is that Jest defines global functions. These globals are only available are runtime so there is no easy way to import them. Is it possible to compile my CLJS without importing the actual modules, perhaps they are mocked in some way, to get through the compilation step? The idea being that when these tests are run, I will have access to the globals because Jest will provide them.
Does js/someGlobal works?
Yup, it totally does. I have no idea why I was thinking that the compiler would try to see if that global exists and just fail because its not there. Thanks!
No problem 😛
what http-lib do you guys usually use for Cljs? I'm thinking about using https://github.com/r0man/cljs-http for my project
@UAZFTL9DK I use that too
@urbanslug you and me then 😉
How would you guys handle it if you had an array of values and wanted to make a network request for each one?
@urbanslug Assuming your network requests are async, you’d probably want to return an array of promises or core.async channels onto which the responses are placed, and then turn that into a collection of resolved values.
I don’t know if there is a function already in core.async like this, but if you have a seq of channels you could use something like
(defn take-chans [chans]
(go
(loop [results []
chans chans]
(if (seq chans)
(recur (conj results (<! (first chans))) (rest chans))
results))))
How you form the seq of channels is another half of the problem, depending on your network request lib, but you’d have it put the responses onto each of a collection of channels.
This is a fairly naïve way to do it, I suspect, but it gets you in the right direction of something that works.
@urbanslug Try
(go (prn (<! (take-chans (map mock-request [1 2 3])))))
This returns a vector of the values produced by mock-request
, so your mock-request
implementation could be revised to simply put the value on the channel. (It appears you have a vector containing a value, so that vector wrapper could be removed, essentially.)
I suppose that what I posted here is lazy, do you could wrap the map
with doall
or use mapv
(to force requests to be initiated eagerly)
I’m curious if there is a better solution than the take-chans
posted above, but it works.
hmmm I tried it out with the mock and it works. with your take chans returning a single channel of requests
Hmm it depends on your problem.
Do you run the code in backend environment (Node.js)
or in the browser?
Do you prefer to handle your errors in a single place
or you would rather to handle the error in the place where you send the request?
Yes. For instance you can take the value from the channel check whether it's an error and then pass it to your error handler. But if you prefer some kind of FRP then promesa might be a good choice https://github.com/funcool/promesa.
Thanks @kwcharllie379 I'll eval both options
I think that if we could take a look into the real sample of code then we would give you better and more accurate advices.