Closed dimitertodorov closed 8 years ago
Hi @dimitertodorov
Do you mind looking at https://github.com/bensu/doo/issues/25 ? Adding the jQuery file as a :foreign-lib
in the compiler options might be what you need.
So, I couldn't get jayq working. But I did get plain jQuery working.
My test task now looks like this:
(deftask test-all []
(comp (testing)
(test-cljs :exit? true
:cljs-opts {:foreign-libs [{:file "jquery/dist/jquery.min.js" :provides ["js.jquery"]}]}
:suite-ns 'torcaui.suite)
(exit!)))
A simple unit test to verify jQuery was loaded in properly would look like this:
(ns torcaui.core-test
(:require-macros [cljs.test :refer [deftest testing is async]]
[dommy.core :refer [sel sel1]])
(:require [cljs.test]
[torcaui.core]
[js.jquery]
[torcaui.app :as app]
[torcaui.routes :as routes]
[torcaui.utils :as utils]
[om.dom :as dom]
[om.core :as om :include-macros true]
[torcaui.components.aside :as aside]
[dommy.core :refer [attr text] :refer-macros [sel sel1]]))
(defn insert-container! [container]
(dommy.core/append! (sel1 js/document :body) container))
(defn new-container! []
(let [id (str "container-" (gensym))
n (.createElement js/document "DIV")]
(set! (.-id n) id)
(insert-container! n)
(sel1 (str "#" id))))
(def jquery (js* "$"))
(defn x []
(->
(jquery "h1.class1")
(jquery "span")
(.text)))
(defn widget [data owner]
(reify
om/IRender
(render [this]
(dom/h1 #js {:id "classes" :className "class1 class2"} nil (:text data)))))
(deftest jquery-works
(let [c (new-container!)]
(om/root widget {:text "Hello world!" :other "Potato"} {:target c})
(let [xv (x)]
(is (= "Hello world!" xv)))))
Closing, since you already came right (with caveats).
Injecting additional JS at the appropriate point is a (boot-)cljs
concern, and should think still solvable without any changes to to this library. But if that's proven incorrect, please reopen.
When requiring jayq.core, PhantomJS complains about missing libraries. Is there a way to pass to PhantomJS external libraries it should load in addition to the CLJS Compiles outputs.
I know this might be a problem with the way JayQ does not package jQuery with itself but relies on you to require it.