0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-10 00:40:30 -05:00

Remove unused code from mixins ns and add concat helper to it.

This commit is contained in:
Andrey Antukh 2016-06-25 17:00:17 +03:00
parent 9c9b0ca908
commit 1dcb19ddfa
No known key found for this signature in database
GPG key ID: 4DFEBCB8316A8B95

View file

@ -1,13 +1,10 @@
(ns uxbox.common.ui.mixins
(:refer-clojure :exclude [derive])
(:require [rum.core :as rum]
(:refer-clojure :exclude [concat])
(:require [sablono.core :refer-macros [html]]
[rum.core :as rum]
[lentes.core :as l]
[goog.dom.forms :as gforms]))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Rum Sugar
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defn component
[spec]
(let [name (or (:name spec)
@ -45,68 +42,11 @@
ref-node (aget (.-refs component) ref)]
(.findDOMNode js/ReactDOM ref-node)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Cursored Mixin
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defn- cursored-key
[state]
(str ":rum/cursored-" (:rum/id state)))
(def ^:private
deref-xform
(map (fn [x] (if (satisfies? IDeref x) @x x))))
(defn- deref-props
[data]
(into [] deref-xform data))
(defn- cursored-did-mount
[state]
(let [key (gensym "foobar")]
(doseq [v (:rum/props state)
:when (satisfies? IWatchable v)]
(add-watch v key
(fn [_ _ _ _]
(rum/request-render (:rum/react-component state)))))
(assoc state ::key key)))
(defn- cursored-will-unmount
[state]
(let [key (::key state)]
(doseq [v (:rum/props state)
:when (satisfies? IWatchable v)]
(remove-watch v key))
(dissoc state ::key)))
(defn- cursored-transfer-state
[old new]
(assoc new
:rum/old-props (:rum/old-props old)
::key (::key old)))
(defn- cursored-should-update
[old-state new-state]
(not= (:rum/old-props old-state) (deref-props (:rum/props new-state))))
(defn- cursored-wrap-render
[render-fn]
(fn [state]
(let [[dom next-state] (render-fn state)]
[dom (assoc next-state :rum/old-props (deref-props (:rum/props state)))])))
(def cursored
{:transfer-state cursored-transfer-state
:should-update cursored-should-update
:wrap-render cursored-wrap-render})
(def cursored-watch
{:did-mount cursored-did-mount
:will-unmount cursored-will-unmount})
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Local Mixin
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defn concat
[& elements]
(html
(for [[i element] (map-indexed vector elements)]
(rum/with-key element (str i)))))
(defn local
"Adds an atom to components state that can be used as local state.
@ -131,10 +71,6 @@
(assoc state key local-state)))
}))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Static Mixin
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(def static
{:should-update
(fn [old-state new-state]