This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-11-18
Channels
- # beginners (84)
- # boot (21)
- # cider (12)
- # cljs-dev (13)
- # cljsrn (3)
- # clojure (169)
- # clojure-dusseldorf (2)
- # clojure-gamedev (6)
- # clojure-germany (1)
- # clojure-russia (15)
- # clojure-serbia (4)
- # clojure-spec (16)
- # clojure-uk (4)
- # clojurescript (51)
- # core-async (1)
- # datomic (23)
- # emacs (16)
- # figwheel (1)
- # fulcro (60)
- # hoplon (8)
- # lein-figwheel (3)
- # leiningen (1)
- # luminus (4)
- # lumo (43)
- # off-topic (4)
- # re-frame (17)
- # rum (37)
- # shadow-cljs (21)
- # test-check (13)
- # vim (14)
Can I ask a dumb question? For a cljs-only (no server, no real .clj files) re-frame app, I serve a myapp/resources/public/index.html with a body element like:
<body>
<div id="app"></div>
<script src="js/compiled/app.js"></script>
<script>myapp.core.init();</script>
</body>
But for a server + re-frame app built from a Luminus template, the same index.html file (when served from a Compojure route and rendered via Selmer) throws an error in the console:
Uncaught ReferenceError: myapp is not defined at (index):30
Any pointers why this is happening?@chris_ there is a race condition. app.js
has to fully load before myapp.core.init()
can be called.
Best option is to change the script
part to be:
<script>window.onload = function () { myapp.core.init(); }</script>
Then init()
will only be called once the app.js
has loaded
@chris_ I've filed a bug report: https://github.com/Day8/re-frame-template/issues/62 (I have no idea how this has not come up before now)
(defn atom? [a]
(satisfies? IAtom a))
or
(defn atom? [a]
(instance? Atom a))
I'm guessing the former is better. But it depends.@cmal undefined?
for example, some API returns an array like [null, undefined, NaN, 3] , and in ClojureScript we want to check whether some value in an array is null, undefined, or NaN.
Eg: (undefined? js/window.bogus)
Also (== something js/NaN)
No wait
No ==
But you have the idea: js/NaN
I just made a mistake: it seems the API cannot return undefined
or NaN
because JSON does not allowed these.
(js/isNaN js/NaN)
should return true
Thanks to you @mikethompson I know how to use undefined?
and js/isNan
and js/NaN
.
Btw, @mikethompson, do you know any posts or books describe javascript interop in detail?
This might help: http://www.spacjer.com/blog/2014/09/12/clojurescript-javascript-interop/
and apart from that a library: https://github.com/binaryage/cljs-oops
Thanks @mikethompson
@cmal @mikethompson also see this: https://clojurescript.org/news/2017-07-14-checked-array-access and try to not use aget
in general
@cmal another good one: http://blog.fikesfarm.com/posts/2017-11-09-avoid-converting-javascript-objects.html
FWIW, misuse of aget
was fixed in the core.async
0.3.465 release yesterday, so one less thing preventing making use of the :checked-arrays
feature https://clojurescript.org/reference/compiler-options#checked-arrays
I'm also happy that, with that release, you can now write (require '[clojure.core.async :refer [chan <! >! go]])
and it will "just work". (No more differences between ClojureScript and Clojure for your ns
forms and core.async
, effectively!)
@mfikes Any tips what would be proper way to solve array length check failure? Assert failed: (< idx (alength array))
I think this is caused by Reagent using an array so that it automatically grows based on the largest used index.
@juhoteperi It is unfortunate that the assert doesn't include the values involved...
I think in this case, array starts as empty but it should grow when new values are added
As an aside, it would be interesting to have an official spec for aset
, which would then be another way to determine what arguments are legal.
Hey, we're trying to figure out how to make reusable reagent components that don't break figwheel in dev, e.g.:
(defn component [& args]
(let [state (r/atom {})] ;; this clears state on every save in dev.
(fn [& args] ;;; uses state in here, for stuff like form values etc.
vs
(defonce component-state (r/atom {})) ;; now my component isn't reusable because all instances will share the same state.
(defn component [& args]
(let [state component-state]
(fn [& args]
i'll try posting this in #reagent too, was just considering if there's a clever macro solution that would help here
@zakpatterson for not breaking figwheel, why not (defn component [state & args] ....) (defonce a-state (r/atom nil)) (defonce b-state (r/atom nil)) [:div (component a-state) (component b-state)]
hm i suppose that's good - it adds an extra thing the user has to be aware of, but i suppose i could just add a variable arity constructor too
I can't think of a version that would be transparent to figwheel without needing seperate tracking of the state outside the component though
they can decide how that atom comes in, and yeah you can make a convenience function if they don't care about figwheel behavior
favorite clojurescript IDEs?
@sova Search for Development Environment on http://blog.cognitect.com/blog/2017/1/31/state-of-clojure-2016-results
thankses @mfikes
@mikethompson Ah, I see; thank you very much! 🙂
Hmmm… Perhaps I’m misunderstanding @mikethompson? The following HTML body also produces an uncaught reference: Uncaught ReferenceError: myapp is not defined at window.onload
<body>
<div id="app"></div>
<script src="js/compiled/app.js"></script>
<script>window.onload = function () { myapp.core.init(); }</script>
</body>
@chris_ Sorry, but it looks like I mislead you. @thheller has taken the time to put me straight https://github.com/Day8/re-frame-template/issues/62#issuecomment-345475898
In which case, the problem has to be either:
1. an :advanced
build without ^:export
on init
(but if you are using the re-frame template this should be handled https://github.com/Day8/re-frame-template/blob/master/src/leiningen/new/re_frame/src/cljs/core.cljs#L20)
2. maybe the namespace for your init
is not really myapp.core
(quite literally check the ns
at the top of where init
is defn-ed)