This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-10-06
Channels
- # beginners (32)
- # boot (17)
- # cider (4)
- # clara (112)
- # cljs-dev (3)
- # cljsjs (2)
- # clojure (222)
- # clojure-germany (3)
- # clojure-greece (1)
- # clojure-italy (4)
- # clojure-losangeles (4)
- # clojure-russia (46)
- # clojure-spec (24)
- # clojure-uk (71)
- # clojurescript (78)
- # community-development (5)
- # component (88)
- # cursive (6)
- # datomic (7)
- # duct (5)
- # figwheel (2)
- # fulcro (21)
- # graphql (22)
- # leiningen (3)
- # luminus (9)
- # off-topic (1)
- # om (16)
- # onyx (46)
- # portkey (30)
- # re-frame (47)
- # reagent (5)
- # remote-jobs (1)
- # ring (12)
- # ring-swagger (13)
- # rum (1)
- # shadow-cljs (81)
- # spacemacs (1)
- # specter (33)
- # sql (2)
- # test-check (2)
- # vim (16)
- # yada (11)
@paytonrules Thanks for help, folks! Actually, the Lambda Island folks sent this yesterday — and they’ve updated the repo accordingly. I now have “lein doo” working — it’s amazing to have automated tests now in CLJS! https://twitter.com/lambdaisland/status/915521175618498560
Does anyone know how to make macros work with cljs.js/eval-str
in a browser-repl? I'm getting TypeError: cljs.spec.alpha.coll_of is not a function
:
cljs.user> (cljs/eval-str
(cljs/empty-state)
"(require '[cljs.spec.alpha :as s])
(s/exercise (s/coll-of keyword?) 2)
;; (s/exercise keyword? 2)"
'user-eval
{:eval cljs/js-eval
:ns 'user-eval
:load (fn [_ cb] (cb {:lang :clj :source ""}))}
(fn [res] (println res)))
{:error #error {:message ERROR, :data {:tag :cljs/analysis-error}, :cause #object[TypeError TypeError: cljs.spec.alpha.coll_of is not a function]}}
nil
If I use the (s/exercise keyword? 2)
line instead, it works great. Also, (s/exercise (s/coll-of keyword?) 2)
works great in the cljs repl when not using eval-str
.@bmaddy My initial hunch is that since your load fn is returning no source, cljs.spec.alpha
is not being loaded into your JavaScript engine.
Another potential concern is that you are evaluating 2 forms in that string. (Your code is probably OK, but I'm more accustomed to the behavior of evaluating a single form at a time, building up state, and putting :context :expr
in the opts map.)
Thanks @mfikes, that's helpful. Do you by chance know where I can find some examples of how that load-fn is supposed to work? I didn't really understand it by reading the cljs.js
source.
@bmaddy You could take a look at the unit tests here https://github.com/clojure/clojurescript/blob/master/src/test/self/self_host/test.cljs
anyone got any clues on how to implement my type as a cljs function, accepting arguments beyond 20 args? clojure's clojure.lang.IFn
protocol has applyTo
which covers the case on my clj implementation, but i have yet to find something similar for my cljs implementation. cljs.core/IFn
only defines -invoke
@anders there’s no way to do that - we never did that works since no one ever asked for it
the compiler isn’t that scary, if you want to try to tackle it you’re more than welcome of course. Lots of knowledgeable people in #cljs-dev if you’re interested in that
maria geller (sp?) gave a nice overview of the cljs compiler a couple years back at the conj or euroclojure or strangeloop or some place, if that helps
https://clojurescript.org/news/2017-07-12-clojurescript-is-not-an-island-integrating-node-modules I'm trying to understand the part about consuming jsx as part of your project. I'm guessing this is somewhat impractical currently if you're also using, e.g. reagent. As you're not using the node version of react, but instead the cljsjs.React namespace, which isn't what it is in node-world. I'm not entirely sure I'm making sense. But essentially, I'd like to use a file from a react 15 project without modification, in an existing cljs project, using babel & such. Trying to figure out how that goes in practice.
say I have 3 namespaces, A
, B
and X
. A
requires X
and B
(in this order), while B
uses X
(but does not require it, for reasons). Can I trust the compiler not to warn about missing namespaces/vars while compiling B
?
In practice, the way that ns
macroexpands seems to allow this (following the order of the dependency lists). There is nothing in the docstring of ns
or require
that leads me to believe that this is required of ns
or require
so I'd consider it implementation specific (and recommend that you make B
require X
if possible).
sadly that's not really possible, or I haven't tried hard enough; the features of B
which make use of X
are gated behind closure defines because I cannot allow X
to be included in regular builds
@dominicm thought of this, but 2 things: 1. can I use both ns
and require
in the same file? 2. require
s have to be top level, but I guess (when SOME_CLOSURE_DEFINE ...)
is special case for the compiler?
@moxaj this seems to work and you can certainly use ns
and require
in the same file. I'm unsure what will happen in an advanced build, you might need to try that out. (at least via the nashorn repl)
@dominicm I specifically meant in cljs. In regular clojure, ns
macroexpands into the same thing as a bunch of require
statements
@moxaj If namespace B
makes use of Vars from namespace X
and it happens to be compiled when X
hasn't yet been loaded, then the compiler should warn.
@mfikes the question then is (assuming all namespaces which require B
AND make use of features which use X
, require X
themselves before) does compilation happen in the same order as the require
s in the ns
forms?
@moxaj At a certain point (we could look up the exact ClojureScript version if important), the compilation partial order was made to satisfy the order specified in ns
forms. But, what's to prevent the compiler from choosing to compile B
first?
@mfikes well, I don't know 🙂 That's why i'm asking, is there a guarantee? Or should this be considered an implementation detail?
(In fact, if :parallel-build
is enabled, then B
could very well be eligible to be compiled in one of the compiler threads, thus causing a race.)
@moxaj When a namespace is compiled, there is now a guarantee that the dependent namespaces are compiled in the order listed in the ns
form. But that is insufficient to prevent B
from being compiled first, given your example, because there is nothing that would cause A
to be compiled first.
@mfikes perhaps you could comment on one of the suggested solutions above (manual "almost-top-level" require
)? It seems to work, but https://anmonteiro.com/2016/10/clojurescript-require-outside-ns/ seems to suggest it shouldn't ("A file can have one of: <...>")
Looking at your example again, @moxaj, it would appear that a legal topological sort is B
, X
, A
@mfikes but can I use both ns
and require
in the same file? If yes, then I shouldn't have to worry about topo sorts
@moxaj I don't think so. In my mind, I think of require
being at the top level as a sugared form of ns
.
Putting require
and an ns
form would be just as legal as putting two ns
forms at the top of your file, I suspect.
@mfikes perhaps worth mentioning that the require
forms would only be included in builds intended for self hosted environments, maybe different rules apply there
@moxaj I'm not aware of any different rules with respect to self-hosted for this kind of stuff.
@moxaj There is some interesting stuff that is done in the spec.gen.alpha
namespace with respect to lazy use of test.check
(see the dynaload
macro), but I'm not sure if that stuff is making use of internal implementation details
It might be useful @moxaj — I'm speculating that you want to make use of some capability in another namespace without explicitly depending on it, but balking if that other namespace has not been loaded. The dynaload
stuff smells very similar.
@mfikes something like that; it's actually library code which would ship a function which makes use of cljs.js
, but this function would only be emitted if a certain closure define is set to a specific value
I don't want to explicitly require cljs.js
because AFAIK that would break advanced builds
trying to come up with something convoluted for convenience is not a good use of time IMO
I suppose, going with David's suggestion, the new resolve
macro could prove useful: If something can be resolved, then the end-user loaded it.
@dnolen at first I almost headdesked, but then I realized: wouldn't this lead to a proliferation of "special" namespaces?
and you won’t come up with some complicated solution and stay focused on providing actual value in your lib 😉
can anyone help in re-learn library for reagent
(def re-learn-component
(re-learn/with-lesson
{:id :basic-lesson
:description "Just testing how to use re-learn"
:position :bottom}
(fn []
[:div
[:div.h3
[:h3 "Ich bin Dhiren Serai"]]])))
(def check-re-learn
(re-learn/with-tutorial
{:id :test-tutorial
:name "check list"
:description "create your learning components"
:lessons [{:id :willkommen
:description [:div
[:h2 "Welcome"]]}
re-learn-component]}
(fn []
[:div
[:h5 "Hallo"]
[re-learn-component]])))
(defn mount-root
;;;Start of the application
[]
(re-learn/init)
(r/render [check-re-learn] (by-id "test")))
(.addEventListener js/document "deviceready"
mount-root
false)