Fork me on GitHub

hi, I am going through chapter four of Reactive with ClojureScript Recipes and am having a little trouble with the following code:

(defn selectors []
    [:select {:id :color}
     (for [opt ["black" "red" "blue"]] [:option {:key opt} opt])]
    [:select {:id :step}
     (for [opt [1 3 5]] [:option {:key opt} opt])]


according to my understanding, the bind-fields function will make sure that the select widgets will reflect the value of :color and :step values in my state, but when I try it in the browser those two values do not get updated


would anyone know why that is? is that perhaps due to some version of the libraries or something?


apparently, this won't work for two reasons: 1. bind-fields needs {:field :list :id iddd} (note field->list specification. 2. selectors function should return another function that returns the hiccup-specified object, like: (defn selectors [] (fn[] [:div....])). That's it

Michael Nardell16:01:45

I am working on getting proficient at ClojureScript, as such interested in simple projects that can be developed in cljs. I am working on a very simple app that will emit XML for a recording scheduling system. I have tried to use the with ClojureScript and always running into problems. Of late I have been working in a Shadow-CLJS environment. I have it enumerated in my shadow-cljs.edn :dependancies, but whenever I try to add it in the apps ns :require I get an error. I had thought from reading the for this project ( that I could use it in my ClojureScript work. Let me know if I am misunderstanding and if so any recommendations for a XML library that can be used in cljs.


What is the error you're getting? And can you copy + paste how you are requiring the library?


Based on my reading of that README, it does seem to support clojurescript

Michael Nardell17:01:59

Alex - sorry for not including the error. I think the problem was due to the dependency not loading; after cleaning up my code the error read something like "Not able to to find cljs for in the classpath" and it suggested that it may be a clj only library. After restarting the shadow-cljs watch and browser-repl processes I got the dependancies to load properly and now appears to be working in my Clojurescipt project. So I suppose that is my question - what is the best way to load/reload dependencies when working in Clojurescript, I am working in Shadow-CLJS right now but I have used Figwheel, and also followed the Clojurescript Quickstart guide. In all of these approaches the area where my understanding is blurriest is connected with dependancies (how and when they are reloaded). I suppose it is a pretty complicated story in cljs, since a dependency could be clj, cljs, or js. Any advice on how to be more comfortable with that concern would be helpfu.

Michael Nardell18:01:16

Retracing my steps, one of the errors that really confused me was this:

Invalid namespace declaration
-- Syntax error -------------------

  (... ... (:require
            [ :refer :all]
has extra input
fixed this by changing to: [ :as :xml]. I was still getting an error with this change, until I forced the dependancies to load.

Michael Nardell20:01:49

Bit more detail on working with in Clojurescript. It seems that some functions are available while others are not. For example emit-str works while indent-str does not - I get the following error: Use of undeclared Var


Restarting the shadow-cljs watch process is the a surefire way to install missing dependencies. There are also tools which can add missing deps/libraries to your active REPL (see as an example). I recall hearing that a new version of Clojure tools has this capability as well, but I'm not familiar with it I believe :refer :all is forbidden in CLJs. In general, it's rare that you need to actually require everything from the namespace and it may make your code harder to read (not knowing where functions are coming from). This is a personal preference though Your anecdote about only being able to use some data.xml functions in CLJs. This is probably why: Note there's both a xml.clj and xml.cljs, and they contain different functions & implementations i.e. indent-str does not exist in xml.cljs

alex03:01:28 mentions some of the reasons behind disabling :refer :all in Cljs

Michael Nardell15:01:50

Thanks - I appreciate the guidance on how / where to look in the source code when these kinds of questions come up.