Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ClojureScript: require "goog.dom query" as q

I'm a bit confused with the import and require semantics..

I'm trying to use the query function inside the dom section of Google's clojure library.

(import '(goog.dom query))
(def q query)

Unfortunately it's not working with require :as :

(require '(goog.dom [query :as q]))

By this chance, I found out that the query function is deprecated. I don't quite get why. I'm just looking for a simple un-fancy abstraction (rather convenient simplification) to make dom manipulations/selections. I know there are tons, I just need a shortcut for not writing helpers like by-id select for every small project.

like image 390
Anton Harald Avatar asked Jan 28 '26 10:01

Anton Harald


1 Answers

You are on the right path. You should use require in this case. Import is for a class that you want to construct.

(ns foo
  (:require [goog.dom :as dom])
  (:import [goog History]))

(dom/getElement "app")
(History.)

If you are using a figwheel repl, you can do this instead

(require 'goog.dom)
(goog.dom/getElement "app")

or

(require '[goog.dom :refer [getElement]])
(getElement "app")

or similar.

query is no longer avaliable, but there are plenty of useful functions like getElement getElementByClass getElementsByTagNameAndClass etc

For repl interaction you might be better using querySelector https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelector instead:

(js/document.querySelector ".myclass")
like image 99
Timothy Pratley Avatar answered Jan 31 '26 04:01

Timothy Pratley



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!