8
votes

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))
1

1 Answers

7
votes

It turns out that

(load-namespace 'project.dom)

works, but require is not implemented yet