This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-04-20
Channels
- # aws (1)
- # beginners (14)
- # boot (30)
- # cider (6)
- # clara (9)
- # cljsjs (3)
- # cljsrn (22)
- # clojure (247)
- # clojure-dusseldorf (75)
- # clojure-france (38)
- # clojure-italy (6)
- # clojure-japan (8)
- # clojure-nl (3)
- # clojure-russia (16)
- # clojure-serbia (4)
- # clojure-spec (1)
- # clojure-uk (53)
- # clojurescript (168)
- # consulting (3)
- # copenhagen-clojurians (1)
- # core-async (7)
- # css (1)
- # datascript (3)
- # datomic (8)
- # dirac (22)
- # events (1)
- # hoplon (2)
- # jobs (1)
- # jobs-discuss (2)
- # leiningen (4)
- # lumo (138)
- # mount (13)
- # nyc (1)
- # off-topic (24)
- # om (34)
- # onyx (15)
- # pedestal (30)
- # re-frame (9)
- # reagent (23)
- # ring (1)
- # ring-swagger (24)
- # rum (6)
- # spacemacs (6)
- # specter (51)
- # uncomplicate (14)
- # unrepl (1)
- # untangled (17)
- # yada (12)
ohh, I think I see what's going on with my externs issue; it doesn't look like cljs parses the @extends
jsdoc tags from gclosure's built-in externs
I get warnings from *warn-on-infer*
from methods that are defined on base classes of HTMLDocument
, like EventTarget
@anmonteiro hoping for v5 UUIDs
@nxqd how would I go about returning the result through a callback? feeling like quite the noob trying to figure out core async
ah you can do something like this:
(defn a [cb]
(go ...
(let [val ..]
(when cb (cb val))))
;; usage
(a
(fn [val]
;; you can use val here
))
May I ask why this not a great way to use core.async? I’m really new to clojure and are trying to learn 🙂
core async is really shine in complicated async operations. We use channel to pass data around. You can look at this example http://swannodette.github.io/2013/11/07/clojurescript-101 . However in the case above, we don't want to pass it anywhere, we just need to use it in current synchronous function ( which is into {} ...
)
is there any way to just block the code on the go block and return the contents of the go block?
I’m working with AsyncStorage
in rn, maybe if i interacted with it directly would callbacks there be easier to block?
@benny you can check these examples https://gist.github.com/shaunlebron/d231431b4d6a82d83628
as far as I can see, there are two ways you can get the value out of block: 1. using cb to return the value 2. send the value to another channel and catch it over there. ( it would be a little bit overkill in your case )
ok, thanks @nxqd i’ll try it out and see which makes more sense, appreciate the pointers!
@benny good reference of how to use core async http://swannodette.github.io/2013/11/07/clojurescript-101 .
hey guys, I'm looking for a good video to send to my friend to convince them to use clojurescript . Any suggestion ?
This gets recommended a lot: https://www.youtube.com/watch?v=gsffg5xxFQI
This is also awesome: https://www.youtube.com/watch?v=j-kj2qwJa_E
they might also appreciate this one. Not so much a marketing video but gives people an idea of how to do various JS things in ClojureScript https://lambdaisland.com/episodes/clojurescript-interop
I found this https://www.youtube.com/watch?v=wq6ctyZBb0A#t=9.273001 to be both very useful and rather compelling
Did anyone build an exception notifier ala figwheel for runtime exceptions in cljs apps? I remember something vaguely, but cannot find it. I have something simple, but the devil is in the details, e.g. properly parsing the stacktrace
hi, in react.js one can pass a callback to setState
funcion. Is there something similar in reagent with reset! some-atom val
?
@tomaas I think that having a callback to reset!
doesn't make sense. Reading the docstring for swap! and reset! suggests that they don't return until applied. So if you do:
(reset! some-atom :val)
(println "guaranteed application: " @some-atom)
But of course, someone could modify the atom before your println. So you should probably do:
(let [new-val (reset! some-atom :val)]
(println new-val) ;; => :foo
)
Though, I guess it's impossible in jsland. Still, code seems more correct with the let.
@dominic, thank you. Didn't know that reset! does not return until it's applied (if I understand correctly, setState in react's jsland is asyncronous, so reset! then returns when setState completes, right?). However, I don't understand the difference between your two snippets. Both of them execute in sequence as js in single thread.
@tomaas I think you may be confused about how reagent's ratom works. It isn't built upon react's state model, so it doesn't use setState under the surface afaik.
I'm using Atom with the linter-clojure plugin. In one of my ClojureScript files, it gives the error "No such namespace: js". Is there any way to fix this? Here's my code, if it matters: https://hastebin.com/ijuluvoduy.cljs (the error is on line 5)
@tech_hutch total aside: you don't need to wrap js/global in an atom 🙂
I know that. I want to change that atom from another namespace.
The js/global
is just a default 🙂
@darwin how so?
Oh, I see
So goog
always contains all globals?
Oh wait, I see
goog.global
contains all globals
goog/global
is an alias for js/window in browser contexts, and node.js global object in node.js
Ah, I see
Thanks
also rememeber that goog
is a pseudo namespace in cljs, you don’t have to require it, it is always available
I didn't know that
Do you have to import subnamespaces, like goog.object
?
How would I refer to require
in node, then? (.-global goog)/require
?
That doesn't look right
this is an implementation detail, but base.js from google closure library must be always present, because cljs modules rely on it (and maybe some other infrastructure)
I know I meant
I was using js/require
How should I refer to it now?
my original reaction was to your usage of js/global, in this case goog/global would be better
you wanted to have a var with a reference to the global object - js/global
works only under node.js, there is no such thing in browser contexts
Oh yeah
I got confused halfway through
But anyway, do you know any way to prevent the linter from throwing an error there?
I suppose requiring the js
or goog
namespace might fix it
Probably
(:require js)
does indeed get rid of the error.
has anyone here used https://github.com/funcool/cats on the frontend? I'm interested in what context you used it
HAHAHAHA
Adding (:require js)
did indeed get rid of the linter error, but it made a compiler error.
I guess you can't require pseudo namespaces.
So I can do something like
(cats.core/alet [foo (async-fn1)
bar (async-fn2)
baz (async-fn3 bar)]
{:foo foo :baz baz})
This will return a promise with a map with the resolved values of foo
and bar
. The cool thing is that in this case, async-fn1
and async-fn2
will be executed in parallel, whereas async-fn3
will be executed after async-fn2
since it relies on the resolved value of bar
.
@grav that should be the front page example for their github as it totally answers "why?"
Btw. funcool’s promesa project also deserves a mention. https://github.com/funcool/promesa
Anyone using lein doo? I suddenly get ERROR: doo was not loaded from the compiled script.
That's from doo
not getting compiled with your build. How are you building your project?
@spinningtopsofdoom I just run lein doo phantom test
, I thought it built it?
Cool... But me I'm stuck. I try to add core.cljs in my core_test.cljs but phantom tells Invariant Violation: _registerComponent(...): Target container is not a DOM element.
lein doo
does compile it. I was wondering with the build's compiler options are.
:compiler {:output-to "out/testable.js"
:target :nodejs
:main intro-lambda.doo-tests
:optimizations :simple}
Oh, now I got somewhere. I tried making it equal to the doo example. And removing :target :nodejs
does the trick it seems
Yep the problem was you were compiling to node
which will break things
glad I could :rubber: 🦆
Hmmm are you trying to register a react app on a DOM structure which doesn't exist (e.g. a bare phantomjs
instance)?
For testing in phantomjs
how are you loading DOM elements e.g.
<body>
<div id="app"></app>
</body>
That doesn't create DOM elements it tells reagent
where to load the component.
lein-cljsbuild is a plugin to give lein cljsbuild awareness. Then there is cljsbuild which appears to go into the :dependencies vector. What is the latter anyway?
You'll need to create a DOM context for your reagent app to render onto.
Here's a JavaScript example of how to do that https://github.com/ariya/phantomjs/blob/master/examples/colorwheel.js
@spinningtopsofdoom I just used some templates (lein new figwheel and lein new chestnut) but I didn't see the need to create a dom
You wouldn't if you were testing in the browser but with phantomjs
you'll need to create the DOM elements
I'm trying to hack together a server generated page as described in https://github.com/reagent-project/reagent-cookbook/tree/master/recipes/reagent-server-rendering
The goal in my case is to have the page load with everything it needs, i.e. not make a callback to the server. I'm thinking of serializing the data the page needs into JSON and shoving that in as an attribute in one of the hiccup tags.
It feels kinda squiggly, if anyone has an alternative idea I'd appreciate hearing it 🙂
How about serializing everything to transit (https://github.com/cognitect/transit-cljs) and putting it in a top level var?
you would compile it into the page in a back-end template
here’s how my prod app does it:
<script>
window.environment_config = {{{environment}}};
</script>
then the ring handler on the back end fills that in with a string, and the cljs parses it at runtime
What's a good cpu heavy computation to test out concurrency on web workers? I'm trying to put together an example app to explain how to use this agent abstraction thing I'm working on.
perhaps a large number of 250+ ms jobs that tend to drag on the main thread, that would be nice to offload on webworkers if it were more convenient...
@john ackermann function
or graph analysis of a large random graph
you could also do ray tracing if there’s a straightforward way to break up the parts into workers
if you want something with visible demonstrable results and not just numbers to crunch
hey all, just wondering as a newbie to clojure(script)...why such the heavy dependency on react and nothing else? Or is the idea that the NPM module support will allow clojurescript a better interop story for other frontend js frameworks?
cljs itself doesn’t depend on react
or is it a more enterprise-y response as in "why recreate the wheel" or "don't fix what isn't broken"
the most popular are om, reagent, re-frame, etc...all the popular ones are all wrappers around react
my impression is that folks like react because it allows controlling render using immutable data
which is much more friendly to clojure dev style than other frontend frameworks I know of
absolutely not
and there is no impact either on the closure compiler? since it's just compiling down your cljs, right?
exactly - I’ve done cljs without react. But react and cljs fit nicely because they have some design decisions that align nicely.
I'm also assuming you lose isomorphism without the native cljs wrappers for react...ie if you just use cljs interop with a js framework
wait...that might be wrong...is there interop between clojure in the backend and clojurescript on the front?
no, all interop is with the host
there’s cljc files that can have code that runs on both clj and cljs - but I wouldn’t expect any code using react to be shared
@imdaveho React is "functional" in nature, so it is an excellent match for clojurescript which explains its popularity.
So, yes, you could absolutely "wrap" Angular and Vue ... there's a good interop story between ClojureScript and js ... but the result would not be as pleasing to clojure sensibilities