From c8c26250820a68d26fe0f2eb1ff3aa4a048fcb25 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Mon, 11 Jan 2016 22:28:56 +0200 Subject: [PATCH] Minor improvement on how colors are rendered in colors library. --- frontend/uxbox/ui/dashboard/colors.cljs | 39 +++++++++++++------------ frontend/uxbox/util/lens.cljs | 8 ++++- 2 files changed, 27 insertions(+), 20 deletions(-) diff --git a/frontend/uxbox/ui/dashboard/colors.cljs b/frontend/uxbox/ui/dashboard/colors.cljs index 4a562e4d9..685ae2986 100644 --- a/frontend/uxbox/ui/dashboard/colors.cljs +++ b/frontend/uxbox/ui/dashboard/colors.cljs @@ -22,17 +22,19 @@ ;; Lenses ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -(def ^:static dashboard-state - (as-> (l/in [:dashboard]) $ - (l/focus-atom $ st/state))) +(def ^:static ^:private dashboard-l + (-> (l/in [:dashboard]) + (l/focus-atom st/state))) -(def ^:static collections-state - (as-> (l/in [:colors-by-id]) $ - (l/focus-atom $ st/state))) +(def ^:static ^:private collections-by-id-l + (-> (comp (l/in [:colors-by-id]) + (ul/merge library/+color-collections-by-id+)) + (l/focus-atom st/state))) -(def ^:static collection-state - (as-> (ul/dep-in [:colors-by-id] [:dashboard :collection-id]) $ - (l/focus-atom $ st/state))) +(defn- focus-collection + [collid] + (-> (l/key collid) + (l/focus-atom collections-by-id-l))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Page Title @@ -46,7 +48,7 @@ (rs/emit! (dd/rename-color-collection collid content)))) (on-delete [e] (rs/emit! (dd/delete-color-collection (:id coll))))] - (let [dashboard (rum/react dashboard-state) + (let [dashboard (rum/react dashboard-l) own? (:builtin coll false)] (html [:div.dashboard-title {} @@ -72,14 +74,15 @@ (defn nav-render [own] - (let [dashboard (rum/react dashboard-state) - colors (rum/react collections-state) + (let [dashboard (rum/react dashboard-l) + collections-by-id (rum/react collections-by-id-l) collid (:collection-id dashboard) own? (= (:collection-type dashboard) :own) builtin? (= (:collection-type dashboard) :builtin) - collections (if own? - (sort-by :id (vals colors)) - library/+color-collections+)] + collections (as-> (vals collections-by-id) $ + (if own? + (filter (comp not :builtin) $) + (filter :builtin $)))] (html [:div.library-bar [:div.library-bar-inside @@ -117,13 +120,11 @@ (defn grid-render [own] - (let [dashboard (rum/react dashboard-state) + (let [dashboard (rum/react dashboard-l) coll-type (:collection-type dashboard) coll-id (:collection-id dashboard) own? (= coll-type :own) - coll (case coll-type - :builtin (get library/+color-collections-by-id+ coll-id) - :own (rum/react collection-state)) + coll (rum/react (focus-collection coll-id)) edit-cb #(lightbox/open! :color-form {:coll coll :color %}) remove-cb #(rs/emit! (dd/remove-color {:id (:id coll) :color %}))] (when coll diff --git a/frontend/uxbox/util/lens.cljs b/frontend/uxbox/util/lens.cljs index bca5f3e53..b3b76a0fa 100644 --- a/frontend/uxbox/util/lens.cljs +++ b/frontend/uxbox/util/lens.cljs @@ -1,5 +1,5 @@ (ns uxbox.util.lens - (:refer-clojure :exclude [derive]) + (:refer-clojure :exclude [derive merge]) (:require [cats.labs.lens :as l])) (defn dep-in @@ -17,6 +17,12 @@ [f] (l/lens f #(throw (ex-info "Not implemented" {})))) +(defn merge + [data] + (l/lens + (fn [s] (cljs.core/merge s data)) + #(throw (ex-info "Not implemented" {})))) + (defn derive [a path] (l/focus-atom (l/in path) a))