roboli
roboli

Reputation: 1478

Clojurescript and Google Closure: How to correctly require a namespace or import a class?

I noticed in the tut Clojurescript 101 that you can use closure classes like:

(ns async-tut1.core
  (:import [goog.net XhrIo]))

But there is a note that says:

Note: import is only for this use case, you never use it with ClojureScript libraries

What does it really mean? As I understand it, you should not import classes this way. Am I correct? If I am, how would you do it then? Many thanks.

Upvotes: 5

Views: 2009

Answers (1)

Joaquin
Joaquin

Reputation: 2744

If you want to import the Closure classes, you use import, if you are importing functions or vars, then you use require or use:

(ns async-tut1.core
  (:require [goog.events :refer [listen] :as ev])
  (:import [goog.net XhrIo]))

What it means is that the import form is specific to the use case of importing classes from the host libraries (google closure modules).

Upvotes: 10

Related Questions