This is certainly trivial, but I could not find it anywhere. I am trying to start fiddling with ClojureScript. I was able to get to a ClojureScript REPL with ClojureScript One.
I can connect with a browser and execute some simple DOM queries and manipulations there. Now I would like to start saving some useful functions into modules and load them as needed. This is where I get stuck.
If I try something like
(require 'project.dom)
I get the exception FileNotFoundException Could not locate project/dom__init.class or project/dom.clj on classpath
. I indeed have only project/dom.cljs
, as I saw all ClojureScript files in the example use this extension.
If I try to rename it to project.clj
, I get a complaint about the missing namespace js
. Of course I use that namespace quite a lot in the module.
What is the proper way to write a simple ClojureScript file that can work with the browser, and load it from the REPL? Anything that will make able to run this simple example will do:
(ns ^{:doc "A module for selecting elements from the DOM."}
project.dom)
(defn get
[selector]
(.querySelectorAll js/document selector))
ClojureScript Built-in REPLs. ClojureScript is a variant of the Clojure language, which compiles (or "transpiles") to JavaScript code. That way you can write Clojure code, but run it anywhere JavaScript is available.
run lein new ... or get a project set up any way you like (an essential setup is just a project. clj and a source file) cd into project; run npm init and set up the npm part. run npm install -D shadow-cljs react react-dom and leave npm land.
It turns out that
(load-namespace 'project.dom)
works, but require
is not implemented yet
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With