Refactored dom and animation out of experimental.

This commit is contained in:
Aaron Craelius 2014-11-16 18:28:29 -05:00
parent 43bf4662c3
commit fd86d23ab3
4 changed files with 7 additions and 129 deletions

View file

@ -1,7 +1,7 @@
(ns freactive.experimental.animation
(ns freactive.animation
(:require
[freactive.core :as r]
[freactive.experimental.dom2 :as dom]))
[freactive.dom :as dom]))
(deftype AnimationEaser [state easing-fn animating on-complete
watches invalidation-watches]

View file

@ -1,4 +1,4 @@
(ns freactive.experimental.dom2
(ns freactive.dom
(:require [freactive.core :as r]
[goog.object])
(:require-macros [freactive.macros :refer [rx non-reactively]]))

View file

@ -1,120 +0,0 @@
(ns freactive.cljs-perf)
(defn bench [f]
(time
(dotimes [i 100000]
(f))))
(defprotocol ITest1
(-do-something [this]))
(extend-type string
ITest1
(-do-something [this]))
(extend-protocol ITest1
js/Object
(-do-something [_]))
(defmulti test1 type)
(defn test1-string [x])
(defn do-test1 [x]
(if (string? x)
(test1-string x)
(test1 x)))
(bench #(satisfies? ITest1 "abc"))
(bench #(-do-something "abc"))
(bench #(do-test1 "abc"))
(def js0 #js {})
(def js1 #js [])
(def clj0 {})
(bench #(set! (.-x js0) 0))
(bench #(aset js1 0 0))
(bench #(assoc clj0 :x 0))
(def element-spec-lookup #js {})
(defprotocol IElementSpec
(-get-virtual-dom [x]))
(defrecord ElementSpec [spec]
IElementSpec
(-get-virtual-dom [x] spec))
(extend-type string
IElementSpec
(-get-virtual-dom [x] x))
(extend-type PersistentVector
IElementSpec
(-get-virtual-dom [x] x))
(defn- dom-node? [x]
(> (.-nodeType x) 0))
(defn- get-virtual-dom [x]
(cond
(dom-node? x)
(get-virtual-dom (aget element-spec-lookup x))
(string? x) x
(vector? x) x
:default (-get-virtual-dom x)))
(defn- get-element-spec [x]
(if (dom-node? x)
(aget element-spec-lookup x)
x))
(defn- get-transition [x transition-name]
(let [spec (get-element-spec x)]
(when-not (string? spec)
(get (meta spec) transition-name))))
(def es0 (ElementSpec. "abc"))
(bench #(get-virtual-dom "abc"))
(bench #(-get-virtual-dom []))
(bench #(get-virtual-dom []))
(bench #(get-virtual-dom es0))
(bench #(get-transition [] :on-show))
(bench #(get-transition "abc" :on-show))
(defprotocol IHasDOMNode
(-get-dom-node [x]))
(defn get-dom-node [x]
(if (dom-node? x)
x
(-get-dom-node x)))
;(defprotocol IDispose
; (-dispose! [x]))
(defprotocol IRemove
(-remove! [x]))
(defn- remove-dom-node [x])
(defn remove! [x]
(if (dom-node? x)
(remove-dom-node x)
(-remove! x)))
()

View file

@ -1,10 +1,10 @@
(ns freactive.dom-perf
(:refer-clojure :exclude [atom])
(:require
[freactive.experimental.dom2 :as dom]
[freactive.dom :as dom]
[freactive.core :refer [atom cursor] :as r]
[figwheel.client :as fw :include-macros true]
[freactive.experimental.animation :as animation]
[freactive.animation :as animation]
[goog.string :as gstring])
(:require-macros
[freactive.macros :refer [rx debug-rx]]))
@ -93,8 +93,7 @@
[:svg/svg
{:width "100%" :height "100%"
:style {:position "absolute" :left 0 :top "20px"}
:viewBox (rx (str "0 20 " @width " " @height))
}
:viewBox (rx (str "0 20 " @width " " @height))}
(circle mouse-x mouse-y)
(let [ease-x (animation/easer 0.0)
ease-y (animation/easer 0.0)]
@ -124,7 +123,6 @@
(dom/mount! (.getElementById js/document "root") (view))
(fw/watch-and-reload)
;;(fw/watch-and-reload)