fix handling of records with ALL in cljs

This commit is contained in:
nathanmarz 2017-06-02 10:17:35 -04:00
parent b66db48a84
commit b2589e00a6

View file

@ -60,6 +60,13 @@
(defn- all-transform-list [structure next-fn] (defn- all-transform-list [structure next-fn]
(doall (sequence (comp (map next-fn) (filter not-NONE?)) structure))) (doall (sequence (comp (map next-fn) (filter not-NONE?)) structure)))
(defn- all-transform-record [structure next-fn]
(reduce
(fn [res kv] (conj res (next-fn kv)))
structure
structure
))
(extend-protocol AllTransformProtocol (extend-protocol AllTransformProtocol
nil nil
(all-transform [structure next-fn] (all-transform [structure next-fn]
@ -129,13 +136,10 @@
(all-transform [structure next-fn] (all-transform [structure next-fn]
(non-transient-map-all-transform structure next-fn (empty structure))) (non-transient-map-all-transform structure next-fn (empty structure)))
#?(:clj clojure.lang.IRecord :cljs cljs.core/IRecord) #?(:clj clojure.lang.IRecord)
#?(:clj
(all-transform [structure next-fn] (all-transform [structure next-fn]
(reduce (all-transform-record structure next-fn)))
(fn [res kv] (conj res (next-fn kv)))
structure
structure
))
#?(:clj clojure.lang.PersistentHashMap :cljs cljs.core/PersistentHashMap) #?(:clj clojure.lang.PersistentHashMap :cljs cljs.core/PersistentHashMap)
(all-transform [structure next-fn] (all-transform [structure next-fn]
@ -184,6 +188,9 @@
#?(:cljs default) #?(:cljs default)
#?(:cljs #?(:cljs
(all-transform [structure next-fn] (all-transform [structure next-fn]
(if (record? structure)
;; this case is solely for cljs since extending to IRecord doesn't work for cljs
(all-transform-record structure next-fn)
(let [empty-structure (empty structure)] (let [empty-structure (empty structure)]
(cond (cond
(and (list? empty-structure) (not (queue? empty-structure))) (and (list? empty-structure) (not (queue? empty-structure)))
@ -202,7 +209,7 @@
:else :else
(into empty-structure (into empty-structure
(comp (map next-fn) (filter not-NONE?)) (comp (map next-fn) (filter not-NONE?))
structure)))))) structure)))))))