Skip to content
Browse files

* .gitignore: latest

  • Loading branch information...
1 parent 78b96ad commit 05d28720a02b8c11360a03e0fa22aed19d3e21eb David Nolen committed
Showing with 81 additions and 5 deletions.
  1. +3 −1 .gitignore
  2. +15 −0 index.html
  3. +4 −3 project.clj
  4. +59 −1 src/cljs_demo/core.cljs
View
4 .gitignore
@@ -5,4 +5,6 @@
pom.xml
*.jar
*.class
-.lein*
+.lein*
+/.DS_Store
+/index.html~
View
15 index.html
@@ -0,0 +1,15 @@
+<html>
+ <head>
+ </head>
+ <body>
+ <script type="text/javascript" src="main.js"></script>
+ <style>
+ #box {
+ width: 100px;
+ height: 100px;
+ background-color: red;
+ }
+ </style>
+ <div id="box"></div>
+ </body>
+</html>
View
7 project.clj
@@ -1,7 +1,8 @@
(defproject cljs-demo "0.1.0-SNAPSHOT"
:description "ClojureScripting!"
- :dependencies [[org.clojure/clojure "1.4.0-beta3"]]
+ :dependencies [[org.clojure/clojure "1.4.0-beta3"]
+ [domina "1.0.0-alpha2"]]
+ :dev-dependencies [[lein-cljsbuild "0.1.2"]]
:cljsbuild {:builds [{:source-path "src"
- :compiler {:output-to "main.js"
- :optimizations :whitespace
+ :compiler {:optimizations :simple
:pretty-print true}}]})
View
60 src/cljs_demo/core.cljs
@@ -1 +1,59 @@
-(ns cljs-demo.core)
+(ns cljs-demo.core
+ (:require [clojure.string :as s]
+ [clojure.browser.repl :as repl]
+ [domina :as d]
+ [domina.css :as dc]))
+
+(repl/connect "http://localhost:9000/repl")
+
+(extend-type js/Element
+ IPrintable
+ (-pr-seq [this options]
+ (let [id (.-id this)
+ id-str (if (not (s/blank? id)) (str " id=\"" id "\"") "")
+ class (.-className this)
+ class-str (if (not (s/blank? class)) (str " class=\"" class "\"") "")]
+ (if id
+ (list "<"
+ (.toLowerCase (.-tagName this))
+ id-str
+ class-str
+ ">")))))
+
+(extend-type js/NodeList
+ ISeqable
+ (-seq [this]
+ (IndexedSeq. this 0))
+ IPrintable
+ (-pr-seq [this options]
+ (-pr-seq (-seq this) options)))
+
+(extend-type js/CSSStyleDeclaration
+ ISeqable
+ (-seq [this]
+ (let [ks (js-keys this)]
+ (into {}
+ (->> ks
+ (filter #(.hasOwnProperty this %))
+ (map #(vector % (aget this %)))))))
+ IPrintable
+ (-pr-seq [this options]
+ (-pr-seq (-seq this) options)))
+
+(def box (d/single-node (dc/sel "#box")))
+
+(comment
+ ;; 100-200ms
+ (let [ss (.-style box)]
+ (dotimes [_ 10]
+ (time
+ (dotimes [_ 1e3]
+ (-seq ss)))))
+
+ ;; 200-300ms
+ (let [ss (.-style box)]
+ (dotimes [_ 10]
+ (time
+ (dotimes [_ 1e4]
+ (js-keys ss)))))
+ )

0 comments on commit 05d2872

Please sign in to comment.
Something went wrong with that request. Please try again.