Skip to content

Commit

Permalink
use arrays instead of vectors when possible
Browse files Browse the repository at this point in the history
  • Loading branch information
roman01la committed Sep 21, 2017
1 parent 9003a02 commit c691940
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/cljss/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
[(nth args idx) value]))
(mapcat identity)
((fn [coll] (concat coll [:else (get styles rule)]))))))
~(mapv second states))])))
(list ~@(mapv second states)))])))
(into {})
(merge styles)
(#(apply dissoc % sprops)))))
Expand All @@ -85,7 +85,7 @@
[var args styles]
(let [[id# static# vals#] (build-styles styles)]
`(defn ~var ~args
(cljss.core/css ~id# ~static# ~vals#))))
(cljss.core/css ~id# ~static# (cljs.core/array ~@(map (fn [v] `(cljs.core/array ~@v)) vals#))))))

(defn- vals->array [vals]
(let [arrseq (mapv (fn [[var val]] `(cljs.core/array ~var ~val)) vals)]
Expand All @@ -101,12 +101,14 @@
[id static values] (build-styles styles)
values (vals->array values)
attrs (->> styles vals (filterv keyword?))]
[tag id static values attrs]))
[tag id static values `(cljs.core/array ~@attrs)]))

(defmacro make-styled []
'(defn styled [cls static vars attrs create-element]
(fn [props & children]
(let [[props children] (if (map? props) [props children] [{} (apply vector props children)])
(let [[props children] (if (map? props)
(array props children)
(array {} (apply array props children)))
var-class (->> vars
(map (fn [[cls v]]
(cond
Expand All @@ -118,7 +120,12 @@

:else (array cls v))))
(cljss.core/css cls static))
meta-attrs (->> vars (map second) (filter #(satisfies? IWithMeta %)) (map meta) flatten set)
meta-attrs (->> vars
(map second)
(filter #(satisfies? IWithMeta %))
(map meta)
flatten
set)
className (:className props)
className (str (when className (str className " ")) var-class)
props (assoc props :className className)
Expand Down Expand Up @@ -162,7 +169,7 @@
[[] [[] [] 1]]))]
[(->> (interleave ks statics)
(apply str))
vals]))
`(cljs.core/array ~@(map (fn [v] `(cljs.core/array ~@v)) vals))]))

(defmacro defkeyframes
"Takes var name, a vector of arguments and a hash map of CSS keyframes definition.
Expand Down

0 comments on commit c691940

Please sign in to comment.